Good Morning,
I am new to scripting in .BAT and I have been tasked with creating a Batch file to:
1) Copy a folder from ‘My Document’ to another location ‘F:\TEST’
2) Recording the time (in a excel log or text file) it take to copy and then paste the folder to its new location
3) Delete the file we just pasted in ‘F:\TEST’
We are doing this to see what the time lag is between copying and pasting a large folder over a network drive at different point though-out the day. At the moment I am really struggling where to start with this and any help will be helpful.
Thank you,
John
.BAT copy and paste with time taken
Moderator: DosItHelp
Re: .BAT copy and paste with time taken
This uses a helper batch file called `getTimestamp.bat` (by dbenham) - download from: https://www.dropbox.com/s/1itzwwxcwqeen ... estamp.bat
Place `getTimestamp.bat` in the same folder as the batch file or in a folder that is on the path.
getTimestamp.bat can be found on this forum also.
Place `getTimestamp.bat` in the same folder as the batch file or in a folder that is on the path.
getTimestamp.bat can be found on this forum also.
Code: Select all
:: get elapsed time
@echo off
call getTimestamp -f {ums} -r t1
echo copying file - please wait...
copy "%userprofile%\my documents\file.ext" "f:\test" >nul
call getTimestamp -f {ums} -r t2
call getTimestamp -d %t2%-%t1% -f "{ud} days {hh}:{nn}:{ss}.{fff}" -u
del "f:\test\file.ext"
pause
Re: .BAT copy and paste with time taken
RoboCopy will do the Copy Delete and Time Taken.
Code: Select all
@Echo off
SetLocal
Set Src=C:\Users\UserName\My Documents\
Set Dst=F:\TEST\
Set Dir=My Folder
Set OutLog=C:\Logs\CopyOput.txt
REM RoboCopy "%Src%%Dir%" "%Dst%%Dir%" /E /MOVE /LOG+:"%OutLog%" /NC /NFL /NDL /NP
RoboCopy "%Src%%Dir%" "%Dst%%Dir%" /E /LOG+:"%OutLog%" /NC /NFL /NDL /NP
RD/S/Q "%Dst%%Dir%"
Last edited by Compo on 29 Jul 2014 10:36, edited 1 time in total.
Re: .BAT copy and paste with time taken
It may need some tweaking compo but is a good idea.
I think the requirement is to copy a single file, measure the time elapsed, and then delete the copied file - so they can repeat the task later.
Your robocopy command seems to copy folders recursively and move the folders.
I think the requirement is to copy a single file, measure the time elapsed, and then delete the copied file - so they can repeat the task later.
Your robocopy command seems to copy folders recursively and move the folders.
Re: .BAT copy and paste with time taken
foxidrive wrote:Your robocopy command seems to copy folders recursively and move the folders.
It was my understanding that ROBOCOPY only does folders. It cannot do a single file.
Re: .BAT copy and paste with time taken
foxidrive wrote:I think the requirement is to copy a single file, measure the time elapsed, and then delete the copied file - so they can repeat the task later.
Your robocopy command seems to copy folders recursively and move the folders.
The original question says
johnbird wrote: 1) Copy a folder from ‘My Document’ to another location ‘F:\TEST’
2) Recording the time (in a excel log or text file) it take to copy and then paste the folder to its new location
3) Delete the file we just pasted in ‘F:\TEST’
We are doing this to see what the time lag is between copying and pasting a large folder over a network drive at different point though-out the day.
My example copies a folder from 'My Documents' to 'F:\TEST', 'outputs a text file' giving the 'time taken' and 'deletes' that which was copied from the source. My mistake therefore was that I was deleting the source folder not the destination folder so I have edited my previous code accordingly.
Re: .BAT copy and paste with time taken
Compo wrote:The original question saysjohnbird wrote: 3) Delete the file we just pasted in ‘F:\TEST’
I was deleting the source folder not the destination folder so I have edited my previous code accordingly.
Yes, you're right Compo. It said folder a few times but I focused on that point 3

Squashman, Robocopy can copy only a filespec when you add it after the target folder, and it can be a single filename.