Saved Bookmarks
| 1. |
Solve : Append date to a file? |
|
Answer» I would like to use the copy /xcopy or RENAME command and take a file and rename it to INCLUDE the date - is that possible. REN [drive:][path]filename1 filename2 Change directories to the directory where the file in question is stored. Then type rename filenamehere.whatevertheextensionis whatyouwantittobenamed.whatevertheexten sionis do you mean datestamp? Code: [Select]for /f "tokens=2-4 delims=/- " %%a in ('date/t') do set date2=%%a%%b%%c you can then use xcopy to rename it to %date2%.ext the date will then be 06252009 if ONLY your date IS in a mm/dd/yyyyC:\>type datename.bat Code: [Select]echo off for /f "tokens=2-4 delims=/- " %%a in ('date/t') do set date2=%%a%%b%%c echo date2 = %date2% copy try.bat try%date2%.bat type try%date2%.bat Output: C:\>datename.bat date2 = 06252009 copy try.bat try06252009.bat 1 file(s) copied. type try06252009.bat ECHO OFF ECHO 1 - Stars ECHO 2 - Dollar Signs ECHO 3 - Crosses echo Enter Choice . . ,as previously said, the date/t command is dependent on regional settings of the computer. either extra batch code need to be written to take CARE of that, or just use tools that take care of that for you automatically. eg VBSCRIPT Code: [Select]Set objFS = CREATEOBJECT("Scripting.FileSystemObject") Set objArg = WScript.Arguments strFile = objArg(0) Set objFile = objFS.GetFile(strFile) today = Now yr = Year(today) mth = Month(today) dy = Day(today) If Len(mth) <2 Then mth="0"&mth End If If Len(dy) <2 Then dy="0"&dy End If strDate = mth&dy&yr newfilename = objFS.GetBaseName(strFile) & "-" & strDate & "." &objFS.GetExtensionName(strFile) objFile.Name = newfilename save the above as test.vbs and on command line Code: [Select]C:\test>cscript /nologo test.vbs file1.txt |
|