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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch to create an incremented fold

Reply to Message Icon

Name: CKotlowski
Date: August 7, 2008 at 16:51:15 Pacific
OS: Vista
CPU/Ram: Dual Core
Product: 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



Sponsored Link
Ads by Google

Response Number 1
Name: Hans Henrik
Date: August 7, 2008 at 23:57:32 Pacific
Reply:

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


0

Response Number 2
Name: CKotlowski
Date: August 8, 2008 at 14:18:24 Pacific
Reply:

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!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch to create an incremented fold

Using VBScript to create an account www.computing.net/answers/programming/using-vbscript-to-create-an-account/15416.html

batch to create desktop shortcut www.computing.net/answers/programming/batch-to-create-desktop-shortcut/5568.html

How to Create an exe file for java www.computing.net/answers/programming/how-to-create-an-exe-file-for-java/6195.html