1.

Solve : creating directory in DOS?

Answer»

hello,

I have a problem with creating a directory in DOS.
I can't create a directory with the form:
"274oct012009thursday" where :
274-is a random number
oct012009 -date
thursday-day
tomorrow the directory will look like:
"275oct022009friday"

Can you help me in this problem? TnxCan you please post your code so we can see why the rand() is malfunctioning maybe? Interesting that it appears to ++ the 274 to 275

Most common issue I have seen with concatinating the info into a single folder name / directory is that you end up with ....\274\oct\01\2009\ where274 BECOMES a directory and the date a series of subdirectories there of.
this code:"

Set FDate=%Date:~-10,10%
Set Fdate=%FDate:/=%

MD d:\users\doru\DOS\%FDate%"

will made a directory with the name:10012009,

but I would like to display 274oct012009thursday.
for tomorrow will display 275oct022009friday, 276oct032009saturday etc



In the following script it is assumed that:
1. The 'random' number to which you refer is in fact a sequential number.
2. The number sequence will commence with 001.
3. All sub-directories of the directory d:\users\doru\dos\ will have been created by the script.
4. Your date is in the format 'day mm/dd/yyyy' eg Fri 10/02/2009 (although the separator / might be another permitted CHARACTER).

The script is untested.

Code: [Select]@echo off
cls
setlocal

:: Set day and YEAR...
set ddyyyy=%date:~7,2%%date:~-4%

:: Convert short day name to long day name...
set day=%date:~0,3%
if /I %day:~0,1% equ M set day=Monday && goto month
if /I %day:~0,1% equ T if /I %day% equ Tue (
set day=Tuesday && goto month
) else (
set day=Thursday && goto month
)
if /I %day:~0,1% equ W set day=Wednesday && goto month
if /I %day:~0,1% equ F set day=Friday && goto month
if /I %day:~0,1% equ S if /I %day% equ Sat (
set day=Saturday
) else (
set day=Sunday
)

:: Convert month number to alpha month....
:month
set month=%date:~4,2%

:: Remove leading zero if it exists...
set /a month=100%month% %% 100

set monthalpha=Jan Feb Mar Apl May Jun Jul Aug Sep Oct Nov Dec

for /f "TOKENS=%month%" %%# in ("%monthalpha%") do (
set month=%%#
)

:: Get next sequential number...
pushd d:\users\doru\dos\ || Echo PUSHD failed job terminated && exit /b

:: After the directory 001* has been created the following line can be removed
:: and directory 000* deleted.

if not exist 000*\ md 000DummyDirectory
for /f "delims=" %%# in ('dir /ad /b /o-n') do (
set lastdir=%%# & goto makedir
)

:: Make new directory...
:makedir
set lastdir=%lastdir:~0,3%

:: Remove leading zeroes if they exist...
:loop
if %lastdir% gtr 0 if %lastdir:~0,1% equ 0 (
set lastdir=%lastdir:~1%
goto loop
)

set /a nextseqnbr=%lastdir%+1

:: Replace leading zeroes...
if %nextseqnbr% lss 10 set nextseqnbr=00%nextseqnbr%
if %nextseqnbr% gtr 10 if %nextseqnbr% lss 100 set nextseqnbr=0%nextseqnbr%

:: md %nextseqnbr%%month%%ddyyyy%%day%

echo New directory to be created = %nextseqnbr%%month%%ddyyyy%%day%

popd
exit /b

the script is interesting but it's not workingYou'll have to be a lot more specific than that. "Not Working" could mean anything from CRASHING on the first command to Pushd failing, to creating the required directory but the date is wrong.

Are there any error messages displayed, have you tried REMing out @echo off to display a listing as the script progresses? Can you determine at what point the script fails?

[Edit] Further thought... Is the 'random/sequential' number the day number in the year? e.g. Oct 3rd 2009 is day number 276 of 2009.



Discussion

No Comment Found