Hello everyone,
I'm hoping someone can help as I'm not the best a creating batch files.
I would like to copy a csv file from a folder and save it in another folder. The source folder is named with today's date (i.e. 06102019) and the destination folder does not change. The CSV will have to overwrite the previous file.
For example:
The batch file will run and look for the folder with today's date
Copy hg200T.csv from C:\monitoring\06102019
Paste (and overwrite existing file) to C:\warning\excel\stream
Thanks in advance
Copying a file from a folder with today's date to another folder.
Moderator: DosItHelp
Re: Copying a file from a folder with today's date to another folder.
You could just use the copy command with the /y-switch (to overwrite the target file without prompting), and use the date environment variable inside a for/f-loop to build the source name. Due to the fact that the date is localized you may have to modify that code , so the following hopefully may helo you (untested; make sure the target is correct and you also might consider to backup the actual target file before running this batch script):
penpen
Code: Select all
@echo off
setlocal enableExtensions disableDelayedExpansion
:: Only works if the date format on your computer matches the german one "11.06.2019",
:: else you have to modifiy which variable is used or which delimiter to choose.
:: To display the format of your date just remove the colons in front of the following command.
:: echo(%date%
for /f "tokens=1-3 delims=." %%a in ("%date%") do (
copy /y "C:\monitoring\%%~b%%~a%%~c\hg200T.csv" "C:\warning\excel\stream"
)
Re: Copying a file from a folder with today's date to another folder.
You can use the wmic command to work around localized date formats.
Steffen
Code: Select all
@echo off &setlocal
for /f %%i in ('wmic os get localdatetime /value') do for /f %%j in ("%%i") do set %%j
copy /y "C:\monitoring\%localdatetime:~4,4%%localdatetime:~,4%\hg200T.csv" "C:\warning\excel\stream\"