Computing.Net > Forums > Programming > Batch file to organise directories

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Batch file to organise directories

Reply to Message Icon

Original Message
Name: mgilson
Date: April 27, 2006 at 23:44:21 Pacific
Subject: Batch file to organise directories
OS: Windows XP
CPU/Ram: AMD Athlon 2400+, 512 MB
Model/Manufacturer: The PC Company, generic
Comment:

I'm trying to write a batch file that will create subdirectories prefixed automatically by the date stamp.

I need the file to ask for a name for the directory when I run it, then it will create the directory combining my input with the system date.

This is probably simple, but I've been working on it for a week and I'm stumped. Can anyone help?


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: April 28, 2006 at 02:21:46 Pacific
Reply: (edit)

First piece of business is to get the sys date.

After that, it gets easier.

Try this:

::== MAKmyDIR.bat
:: make dir prefixed with ymd

@echo off

cls
setlocal
call :sub1
echo new directory name?
set /p ndn=
md "%YYYYMMDD%%ndn%"
goto :eof

:sub1

:: YYYY getter
> syyyy.d echo a 100
>> syyyy.d echo mov ah,2a
>> syyyy.d echo int 21
>> syyyy.d echo.
>> syyyy.d echo p=100 2
>> syyyy.d echo n sizeYYYY
>> syyyy.d echo w
>> syyyy.d echo q
debug < syyyy.d > nul
:: OK

:: MM getter
> sMM.d echo a 100
>> sMM.d echo mov ah,2a
>> sMM.d echo int 21
>> sMM.d echo mov cx,0
>> sMM.d echo mov cl,dh
>> sMM.d echo.
>> sMM.d echo p=100 4
>> sMM.d echo n sizeMM
>> sMM.d echo w
>> sMM.d echo q
debug < sMM.d > nul
:: OK

:: DD getter
> sDD.d echo a 100
>> sDD.d echo mov ah,2a
>> sDD.d echo int 21
>> sDD.d echo mov cx,0
>> sDD.d echo mov cl,dl
>> sDD.d echo.
>> sDD.d echo p=100 4
>> sDD.d echo n sizeDD
>> sDD.d echo w
>> sDD.d echo q
debug < sDD.d > nul
:: OK
del *.d

for %%F in (sizeYYYY sizeMM sizeDD) do call :sub1 %%F
set /p YYYY=<sizeYYYY.#
set /p MM=<sizeMM.#
if %MM% LSS 10 set MM=0%MM%
set /p DD=<sizeDD.#
if %DD% LSS 10 set DD=0%DD%
del size*.*
set YYYYMMDD=%YYYY%%MM%%DD%

goto :eof

:sub1

> %1.# echo %~z1
goto :eof
:: DONE

NOTE: for anyone else reading along here, this will NOT work in DOS; only NT.



If at first you don't succeed, you're about average.

M2


Report Offensive Follow Up For Removal







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








Do you own an iPhone?

Yes
No, but soon
No


View Results

Poll Finishes In 7 Days.
Discuss in The Lounge
Poll History




Data Recovery Software