

InterviewSolution
Saved Bookmarks
1. |
Solve : Rename a set of files and move them? |
Answer» Hi I have a 3 files in C:\test Are these the only files in C:\test\ or are these the only .txt files in C:\test\ ? Hi Dusty these are the only filesThe inclusion of VB script ALLOWS the script to be used with any date FORMAT. If your permissions do not allow its use please post your date format. When you have finished testing change the Copy command to Move. The script is not fully tested. The final two lines can be removed at your discretion. Note that no allowance is made for AM or PM so, if you use that time format, there's a remote possibility that you could overwrite files created at a given time AM with files created at the same time PM. Good hunting. Code: [Select]@echo off cls setlocal :: EXTRACT date/time and set filename prepend. This can be used with :: any date format. set vbsfile=%temp%\vbsfile.vbs ( echo Thisdate = (Date(^)^) echo DateYear = DatePart("YYYY", Thisdate^) echo DateMonth = DatePart("M" , Thisdate^) echo DateDay = DatePart("D" , Thisdate^) echo TimeHour = HOUR(Time^) echo TimeMinute = Minute(Time^) echo Wscript.Echo DateYear^&" "^&DateMonth^&" "^&DateDay^&" "^&Time^ Hour^&" "^&TimeMinute )>>%vbsfile% for /f "tokens=1-5" %%A in ('cscript //nologo %vbsfile%') do ( set yyyy=%%A set mm=%%B set dd=%%C set hh=%%D set mn=%%E ) Del %vbsfile% if %mm% lss 10 if %mm:~0,1% neq 0 set mm=0%mm% if %dd% lss 10 if %dd:~0,1% neq 0 set dd=0%dd% if %hh% lss 10 if %hh:~0,1% neq 0 set hh=0%hh% if %mn% lss 10 if %mn:~0,1% neq 0 set mn=0%mn% set Prepend=%yyyy%%mm%%dd%%hh%%mn%_ :: Move (Copy) files to archive folder. pushd c:\test\ || echo Pushd failed - job terminated && exit /b if not exist c:\testarchive md c:\testarchive for /f "delims=*" %%1 in ('dir /b *.txt') do ( copy %%1 c:\testarchive\%prepend%%%1 > nul ) popd :: Display updated content of archive folder. dir /tw testarchive\ |
|