# Batch Files



## abercabkar (Sep 25, 2001)

I beleive there is a way to create a .bat file to create folders within Windows Explorer. I need to create a sequence of folders named "100" thru to "299" then another sequence called "300" to "499" etc. With in these folder I need 2 sub folder created called "In" and "Out". If there is a way of doing this, I would appreciate an idiots guide, not very good with DOS.


----------



## Max19 (Jul 31, 2001)

The commands in the batch file would be:

md c:\100
md c:\100\In
md c:\100\Out
md c:\101
md c:\101\In
md c:\101\Out

If you're looking for a way to automate this, the only suggestion I'd have would be to use a programming language like Visual Basic. Then you could use For-Next loops with variables. I don't think you'll find an easy way to do this with a batch file.


----------



## MacFromOK (Mar 19, 2001)

I agree with Max on this, there's no way to
increment numbers like this in a batch file
without a utility like PC magazine's
BATCHMAN or something similiar.

There is a free 16-bit version of VDS. It won't
make compiled executables, but you can
call the interpreter with the script file as a
command parameter, and create a shortcut
to it. Check the link in my signature if you're
interested.

The free version is kind of a "Windows batch
utility", but it does math and a lot of stuff a
batch file can't do alone.

Cheers, Mac


----------



## Ratboy (Feb 12, 1999)

The batch file attached will create the needed folders. I named it *makeit.txt* so that I could include it as an attachment. Save it to your HDD and rename it whatever you like with a *.bat extension (ex. makeit.bat).

The two important sections are as follows:

At the beginning of the file:

*ECHO Creating Folders...
set E2=0
set E1=9
set E0=9
:START
IF %E2%%E1%%E0%==299 GOTO END*

E2; E1; E0 is set to one less than the starting point. In this case 099.

The IF statement indicates the last folder that should be created. In this case 299.

At the end of the file:

*:MAKE
md c:\"temp"\%E2%%E1%%E0%
md c:\"temp"\%E2%%E1%%E0%\In
md c:\"temp"\%E2%%E1%%E0%\Out*

This creates the folder and the In & Out sub folder. You will want to replace the temp directory with whatever directory you would want the folders in.

I found the main incrementation batch file here:

http://www.ericphelps.com/batch/samples/addition.txt


----------



## Ratboy (Feb 12, 1999)

This one will create the 300 - 499 folders.


----------



## MacFromOK (Mar 19, 2001)

VERY nice Ratboy. 

I've always used batch utilities (even made a few),
so I never considered doing anything like this, but
I played around with this idea a while and made
this count procedure that goes from 000-1000.
You can set the "max" variable for the count limit
(add "D" digits and code if ya need more than 1000).

```
rem -- Do NOT set "max" above 1000, if less than
rem -- 1000, "max" must be 3 digits (009, 043, etc.).
rem -- D1 = 1s, D10 = 10s, D100 = 100s
@ECHO OFF
SET D1=0
SET D10=0
SET D100=0
SET max=1000

:COUNT
  echo %D100%%D10%%D1%
  if "%D1%"=="9" SET D1=10
  if "%D1%"=="8" SET D1=9
  if "%D1%"=="7" SET D1=8
  if "%D1%"=="6" SET D1=7
  if "%D1%"=="5" SET D1=6
  if "%D1%"=="4" SET D1=5
  if "%D1%"=="3" SET D1=4
  if "%D1%"=="2" SET D1=3
  if "%D1%"=="1" SET D1=2
  if "%D1%"=="0" SET D1=1
  if "%D100%%D10%%D1%"=="%max%" goto END
  if not "%D1%"=="10" goto COUNT
  SET D1=0
  if "%D10%"=="9" SET D10=10
  if "%D10%"=="8" SET D10=9
  if "%D10%"=="7" SET D10=8
  if "%D10%"=="6" SET D10=7
  if "%D10%"=="5" SET D10=6
  if "%D10%"=="4" SET D10=5
  if "%D10%"=="3" SET D10=4
  if "%D10%"=="2" SET D10=3
  if "%D10%"=="1" SET D10=2
  if "%D10%"=="0" SET D10=1
  if "%D100%%D10%%D1%"=="%max%" goto END
  if not "%D10%"=="10" goto COUNT
  SET D10=0
  if "%D100%"=="9" SET D100=10
  if "%D100%"=="8" SET D100=9
  if "%D100%"=="7" SET D100=8
  if "%D100%"=="6" SET D100=7
  if "%D100%"=="5" SET D100=6
  if "%D100%"=="4" SET D100=5
  if "%D100%"=="3" SET D100=4
  if "%D100%"=="2" SET D100=3
  if "%D100%"=="1" SET D100=2
  if "%D100%"=="0" SET D100=1
  if "%D100%%D10%%D1%"=="%max%" goto END
  if not "%D100%"=="10" goto COUNT
  goto END

:END
  echo %D100%%D10%%D1%
```
Cheers, Mac 

* BTW (on closer inspection), this goes to 1000
because of going from 9 to 10 on the D100 var.
So you can set "max" to 1000 if you want. I
changed the post to reflect this.
*


----------



## The DOS Machine (Jul 15, 2000)

Man, you guys are good at batch!
 










*-DOSMAN*


----------



## motorfreak (Jun 28, 2004)

Hi Guys, Im new to this site, so bare with me.

I have a question on batch files, a bit like the one in this thread about creating directories but slightly a bit more advanced...

Ok, scenario, I have a digital camera which when linked to my PC creates a new drive for instance, E:, and in the folder is my pictures.

I want to be able to create a batch file to copy the images to a folder on my hard drive and put them in their date order.... Sounds pretty simple, but the file names are the same, and when I try to copy newer images from the camera to the same folder it recognises the same names and trys to overwrite them, so I need to either create a new folder or rename the older files.

Any help would be most grateful.....

Thanks
Dan


----------



## codejockey (Feb 11, 2002)

Motorfreak: have a look at http://forums.techguy.org/t175994 for two versions of a script that will extract elements of the system date and place them in environment variables (which can then be used by other batch files (or the same batch file) to create folders, etc.).

Hope this helps.


----------



## motorfreak (Jun 28, 2004)

Thanks Codejockey, will have a look.

I think I may have already sorted it out now. Where as you can download and rename the images to a dated folder, but if you download again on the same day it will overwrite still, so you have to do it on different days.

I will try this thread though.

Thanks again, you've been a good help.


Motorfreak.


----------



## guard (Jun 18, 2004)

You can use #LogDate  and #LogTime  to rename the files and to make date coded folders. See the examples at *%.GetLogDate%* and *%.GetLogTime%*.

These commands are in the FREE Advanced NT/2K/XP/K3 Command Library.


----------



## motorfreak (Jun 28, 2004)

thanks guard, will look into it.


----------

