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.
Create Folder from the name of file and move file
Moderator: DosItHelp
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