I need to move a file to an existing folder and rename it using the current date, time, and year. The file being moved will always have the same name and extension before being moved, and will always be moved to the same folder. I would like to use a bat file or VB script if possible so that the task can be automated to run every day. Thanks
olddude
@echo off > newfile & setLocal enableDELAYedeXpansion for /f "tokens=* delims= " %%a in ('dir/b newfile') do (
move myfile.ext "d:\%%~Ta.ext"
)
=====================================
Life is too important to be taken seriously.M2
May be this is what you are asking...
@echo offset source=Your existing file name
set destination=Your destination. like@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)FOR /F %%A IN ('TIME/T') DO SET Now=%%A
move %source% %destination%\%Year%-%Month%-%Day%-%now%.ext
Subhash Chandra.
No point trying to guess the date layout.
=====================================
Life is too important to be taken seriously.M2
Thanks. That moves the file just fine. I also need to replace the name with the current date and time when it is moved. Any way to do that in the same batch file? oldguy
I am getting the error below FOR /F %%A IN ('TIME/T') DO SET Now=%%A
%%A was unexpected at this time.Below is the batch file with file names and location included. Any suggestions?
@echo offset source=d:\itlab transfer\test.txt
set destination=d:\itlab transfer\temp\. like@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)FOR /F %%A IN ('TIME/T') DO SET Now=%%A
move %test.txt% %d:\itlab transfer\test%\%Year%-%Month%-%Day%-%now%.ext
Date format is not critical. Since there will only be one file a day I'm looking to make it unique using the date it was created. oldguy
Seems you modified the code a little bit...
============================================================@echo off
FOR /F "tokens=1,2 delims=:" %%A IN ('TIME/T') DO SET Now=%%A-%%B
set source=d:\1.txt
set destination=d:\temp
For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do (
Set Month=%%A
Set Day=%%B
Set Year=%%C
)move %source% "%destination%\%Year%-%Month%-%Day%-%now%.txt"
===========================================================
Just change the value of below 2 lines.put the proper paths after the = sign.set source=d:\1.txt
set destination=d:\tempand in last line .txt (change .txt to the actual extention of the file.)
Subhash Chandra.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |