Script to create directory structure

Reply

Join Date: May 2007
Posts: 21
Reputation: ashkash is an unknown quantity at this point 
Solved Threads: 0
ashkash ashkash is offline Offline
Newbie Poster

Script to create directory structure

 
0
  #1
Mar 13th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 7
Reputation: boristhemoggy is an unknown quantity at this point 
Solved Threads: 0
boristhemoggy's Avatar
boristhemoggy boristhemoggy is offline Offline
Newbie Poster

Re: Script to create directory structure

 
0
  #2
Mar 13th, 2009
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
Our brains haven't evolved to cope with the complexity of the world we've built!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 36
Reputation: mittelgeek is an unknown quantity at this point 
Solved Threads: 0
mittelgeek's Avatar
mittelgeek mittelgeek is offline Offline
Light Poster

Re: Script to create directory structure

 
0
  #3
Mar 25th, 2009
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)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC