Page 1 of 1
COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Posted: 11 Jan 2023 01:19
by xiro
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?
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Posted: 11 Jan 2023 04:52
by Lucky4Me
you can do it this way!
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%
check xcopy /? for options
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Posted: 11 Jan 2023 07:21
by atfon
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
Posted: 12 Jan 2023 01:00
by xiro
Lucky4Me wrote: ↑11 Jan 2023 04:52
you can do it this way!
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%
check xcopy /? for options
I have added this it work for my first objective.
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
Posted: 12 Jan 2023 04:23
by Lucky4Me
For network, use robocopy.
Code: Select all
robocopy "C:\Users\Administrator\Downloads\%foldername%" "\\server1\x$\Backup\Testlink VM Backup\%foldername%"
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
Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER
Posted: 12 Jan 2023 23:16
by xiro
Lucky4Me wrote: ↑12 Jan 2023 04:23
For network, use robocopy.
Code: Select all
robocopy "C:\Users\Administrator\Downloads\%foldername%" "\\server1\x$\Backup\Testlink VM Backup\%foldername%"
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
Project was done I added an additional feature instead of copy I use CUT so I used the MOVE command. Thanks for the help guys