Hello I copy a batch file that can create a folder then name the folder with the current system date and time
Sample
@echo off
for /f "skip=1" %%i in ('wmic os get localdatetime') do if not defined fulldate set fulldate=%%i
set year=%fulldate:~2,4%
set month=%fulldate:~4,2%
set day=%fulldate:~6,2%
set foldername=LOG-%month%-%day%-%year%
md %foldername%
The batch file when click automatically creates a folder with the system date and time as folder name OK done
My question now is how to automatically paste the copied file to the newly created folder? What code is to be added to this batch file? Tried using robocopy [source] [destination] path to md %foldername%.
Does anyone know how to solve this?
COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Moderator: DosItHelp
COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Last edited by xiro on 12 Jan 2023 01:00, edited 1 time in total.
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
you can do it this way!
check xcopy /? for options
Code: Select all
@echo off
for /f "skip=1" %%i in ('wmic os get localdatetime') do if not defined fulldate set fulldate=%%i
set year=%fulldate:~2,4%
set month=%fulldate:~4,2%
set day=%fulldate:~6,2%
set foldername=LOG-%month%-%day%-%year%
md %foldername%
xcopy *.log %foldername%
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Since WMIC has been deprecated in Windows 10 and is expected to be removed in Windows 11, a more robust way to capture the date would be something like the following:
Code: Select all
for /f "tokens=1-3 delims=/: " %%a in ('%__APPDIR__%Robocopy.exe "|" . /njh ^| find ":"') do set "foldername=LOG-%%b-%%c-%%a"
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
I have added this it work for my first objective.Lucky4Me wrote: ↑11 Jan 2023 04:52you can do it this way!
check xcopy /? for optionsCode: Select all
@echo off for /f "skip=1" %%i in ('wmic os get localdatetime') do if not defined fulldate set fulldate=%%i set year=%fulldate:~2,4% set month=%fulldate:~4,2% set day=%fulldate:~6,2% set foldername=LOG-%month%-%day%-%year% md %foldername% xcopy *.log %foldername%
xcopy "C:\Users\Administrator\Downloads\*.xlsx" "%foldername%"
Second ojective is to paste that same folder to another pc in the network
xcopy "%foldername%" "\\server1\x$\Backup\Testlink VM Backup" /xo
xcopy "C:\Users\Administrator\Downloads\%foldername%" "\\server1\x$\Backup\Testlink VM Backup" /xo <-- those did not work I have already shuffle the command but it did not copy the newly created folder even if I have added the attirbute /xo in the robocopy
Anyone here can follow my simple script?
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
For network, use robocopy.
if you don't put %foldername% at the end of "\\server1\x$\Backup\Testlink VM Backup\%foldername%", then it will put all the files (without directory) in the map "\\server1\x$\Backup\Testlink VM Backup"
robocopy /? for options
Code: Select all
robocopy "C:\Users\Administrator\Downloads\%foldername%" "\\server1\x$\Backup\Testlink VM Backup\%foldername%"
robocopy /? for options
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Project was done I added an additional feature instead of copy I use CUT so I used the MOVE command. Thanks for the help guysLucky4Me wrote: ↑12 Jan 2023 04:23For network, use robocopy.
if you don't put %foldername% at the end of "\\server1\x$\Backup\Testlink VM Backup\%foldername%", then it will put all the files (without directory) in the map "\\server1\x$\Backup\Testlink VM Backup"Code: Select all
robocopy "C:\Users\Administrator\Downloads\%foldername%" "\\server1\x$\Backup\Testlink VM Backup\%foldername%"
robocopy /? for options