Create Folder from the name of file and move file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jose_c27
Posts: 1
Joined: 30 Jan 2009 10:52

Create Folder from the name of file and move file

#1 Post by jose_c27 » 30 Jan 2009 13:31

Hi everyone,

I have a list of files in the Root C:, i wanna if its possible to read the first 12 character of the name of a file, and from that create a folder and then move the file to that folder. :?


Example

File:
000000015894001_1.doc
000000015894001_2.doc
000000015894001_3.doc
000000045788001_1.doc
000000045788001_2.doc
000000045788001_3.doc

Create Folders From Name of Files:
000000015894
000000045788

And move the files inside the folders
Folder: 000000015894
Files--
000000015894001_1
000000015894001_2
000000015894001_3
Folder: 000000045788
000000045788001_1
000000045788001_2
000000045788001_3


Thnks in Advance.

DccD
Posts: 23
Joined: 26 Aug 2009 19:34

#2 Post by DccD » 26 Aug 2009 23:38

This should do the trick:

Code: Select all

@echo off

FOR %%A IN (*.doc) DO call :loop %%A
goto end
:loop
set file=%1
set file=%file:~0,12%
md %file% 2>nul
move /Y %1 %file% 2>nul
goto :EOF

:end

Post Reply