943,649 Members | Top Members by Rank

Ad:
Mar 13th, 2009
0

Script to create directory structure

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ashkash is offline Offline
24 posts
since May 2007
Mar 13th, 2009
0

Re: Script to create directory structure

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
Last edited by boristhemoggy; Mar 13th, 2009 at 5:25 pm. Reason: I messed up :P
Reputation Points: 10
Solved Threads: 0
Newbie Poster
boristhemoggy is offline Offline
7 posts
since May 2006
Mar 25th, 2009
0

Re: Script to create directory structure

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.

Ex:
Shell Scripting Syntax (Toggle Plain Text)
  1. for /f "delims=." %%n in ('dir /b *.exe') do (md %%n >nul 2>&1
  2. move *.exe %%n)
Reputation Points: 10
Solved Threads: 0
Light Poster
mittelgeek is offline Offline
37 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: turn mb to gb!
Next Thread in Shell Scripting Forum Timeline: writing part of files and filenames to a new file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC