COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
xiro
Posts: 34
Joined: 21 May 2014 00:17

COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER

#1 Post by xiro » 11 Jan 2023 01:19

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? :?:
Last edited by xiro on 12 Jan 2023 01:00, edited 1 time in total.

Lucky4Me
Posts: 24
Joined: 21 Oct 2020 06:33

Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER

#2 Post by Lucky4Me » 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

atfon
Posts: 178
Joined: 06 Oct 2017 07:33

Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER

#3 Post by atfon » 11 Jan 2023 07:21

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"

xiro
Posts: 34
Joined: 21 May 2014 00:17

Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER

#4 Post by xiro » 12 Jan 2023 01:00

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?

Lucky4Me
Posts: 24
Joined: 21 Oct 2020 06:33

Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER

#5 Post by Lucky4Me » 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

xiro
Posts: 34
Joined: 21 May 2014 00:17

Re: COPY FILES TO SYSTEM DATE CREATED FILENAME FOLDER

#6 Post by xiro » 12 Jan 2023 23:16

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 :)

Post Reply