

InterviewSolution
1. |
Solve : How to add date to folder in batch-file? |
Answer» I need a little bit help with batch-files: how can I rename a folder in a bat-file so that it CONTAINS a current date - such as folder1_20090108 (or any other date string format)? Without the need of typing the date myself, of course It's always difficult when we do not know the format of your date which you didn't advise. Here is a rename if your date format is 'day mm/dd/yyyy' - not tested. Thanks for the code. My mistake, I didn't explain the ORDER of numbers at example in my post - I did indeed mean format yyyymmdd. -JussiDusty MEANS, you need to tell us the local date format you are using. You can see it using the date /t command. For example my local settings make the date look like this Code: [Select]C:\>date /t 09/01/2010 Or use a vbs / batch hybrid which is locale - independent Code: [Select]@echo off Echo Wscript.echo eval(WScript.Arguments(0))>evaluate.vbs For /f "delims=" %%Y in ( ' cscript //nologo evaluate.vbs "year(date)" ' ) do set yyyy=%%Y For /f "delims=" %%M in ( ' cscript //nologo evaluate.vbs "month(date)" ' ) do set mm=%%M For /f "delims=" %%D in ( ' cscript //nologo evaluate.vbs "day(date)" ' ) do set dd=%%D del evaluate.vbs if %mm% LSS 10 set mm=0%mm% if %dd% LSS 10 set dd=0%dd% set datestamp=%yyyy%%mm%%dd% echo Datestamp is %datestamp% Code: [Select]Datestamp is 20100109 |
|