I have a number of files in a folder that are number as 1, 2, 3, 4, 5, 6, etc. I also have a text file in the same folder that identifies each of these numbered files and gives their path location. The text file looks like this:

1 C:\system\Apps\file1.exe
2 C:\system\Apps\file2.exe
3 C:\system\Data\file3.exe
4 C:\system\Data\file4.exe

I need a script that would take this text file and create the correct file directory structure. So in my example, the text file would be taken and then two folders would be created, Apps and Data. 1 and 2 would be placed in Apps and 3 and 4 would be placed in Data. And also 1 should be renamed as file1.exe, 2 should be renamed as file2.exe, etc.

Is this possible to do. I have no experience with scripting and do not even know where to start. I have a lot of files that need to be sorted like this and thought it might be faster using a script than doing it by hand. Any help is appreciated. Thanks.

9 Years
Discussion Span
Last Post by mittelgeek

For /F "delims=." %%n in ('Dir /B *.exe') Do (MD %%n
move *.exe %%n)
Stick that in a batch file and it will do what you want


You may want to include >nul 2>&1 at the end of the md as the script will undoubtedly list errors after creating the directory the first time.


for /f "delims=." %%n in ('dir /b *.exe') do (md %%n >nul 2>&1
move *.exe %%n)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.