Computing.Net > Forums > Programming > Batch to create an incremented fold

Batch to create an incremented fold

Reply to Message Icon

Original Message
Name: CKotlowski
Date: August 7, 2008 at 16:51:15 Pacific
Subject: Batch to create an incremented fold
OS: Vista
CPU/Ram: Dual Core
Model/Manufacturer: Toshiba Satellite
Comment:

I am a novice creating batch files... I needed some expert help creating a batch file that creates a sequential, uniquely named subfolder... under each unique subfolder encountered in a given directory. I did not want the root or files within the folders to be modified... I just wanted the files to end up under a new, incremented folder... grouped by what subfolder they originally were in.

For example, given these folders/files:

C:\MainFld\MySubFldA\MyFile1.txt
C:\MainFld\MySubFldB\MyFile2.xls
C:\MainFld\MySubFldC\MySubSubFldA\MyFile3.doc
C:\MainFld\MySubFldC\MySubSubFldA\MyFile4.doc
C:\MainFld\MySubFldC\MySubSubFldB\MyFile5.mdb
C:\MainFld\MySubFldC\MySubSubFldB\MyFile6.mdb

I needed to have the folder structure changed to this:

C:\MainFld\MySubFldA\Fld1\MyFile1.txt
C:\MainFld\MySubFldB\Fld2\MyFile2.xls
C:\MainFld\MySubFldC\MySubSubFldA\Fld3\MyFile3.doc
C:\MainFld\MySubFldC\MySubSubFldA\Fld3\MyFile4.doc
C:\MainFld\MySubFldC\MySubSubFldB\Fld4\MyFile5.mdb
C:\MainFld\MySubFldC\MySubSubFldB\Fld4\MyFile6.mdb

Etc... for everything under C:\MyMainFld...

I also wanted the batch file to "remember" the last "Fld" number it left off with after a run. For example, after running once and going through all folders, it then sends the last "Fld" number used to a text or temp file... then if the batch file is run again in the future, it reads the temp file and starts the incrementing at that number.

Is this possible to create?? I thank you for your time and help in advance.

CK


Report Offensive Message For Removal

Response Number 1
Name: Hans Henrik
Date: August 7, 2008 at 23:57:32 Pacific
Subject: Batch to create an incremented fold
Reply: (edit)

would be allot easier with numbers, rather than A/B/C (tho thats also possible, but would take some work :p)

an example of making it work with A/B/C would be like

@echo off
cls
:sets
set 1=A
set 2=B
set 3=C
set /A Counter=0
:begin
set /A Counter=%Counter%+1
cd YourMainFolder
md NewFolder%%Counter%% << would create NewFolderA on first loop, NewFolderB on second loop~
if Counter == 5 goto end << would end the loop when ran 5 times
goto begin
:end
echo all done...
pause
exit

and here would be a example of create numbers by ... incremental numbers

@echo off
cls
:sets
set /A Counter=0
:begin
cd YourMainFolder
md NewFolder%Counter% << would create NewFolder 1 on first loop, NewFolder2 on second loop~
if %Counter% == 5 goto end
goto begin
:end
echo all done
pause
exit


Report Offensive Follow Up For Removal

Response Number 2
Name: CKotlowski
Date: August 8, 2008 at 14:18:24 Pacific
Subject: Batch to create an incremented fold
Reply: (edit)

Thank you for your time and help, and for the batch file!

The batch file is good for creating incremented folders under the main folder... but how could I use it to create new folders under all subfolders encountered. I'm not able to give an exact name for the subfolders, since they will be changing periodically. Also, how would I get it to loop through until all subfolders were seen... instead of looping a predefined number of times (like 5)...

Thank you again for all of your help with this. I appreciate it a lot!


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch to create an incremented fold

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software