.BAT copy and paste with time taken

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
johnbird
Posts: 1
Joined: 28 Jul 2014 04:29

.BAT copy and paste with time taken

#1 Post by johnbird » 28 Jul 2014 04:41

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: .BAT copy and paste with time taken

#2 Post by foxidrive » 28 Jul 2014 05:02

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.

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

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: .BAT copy and paste with time taken

#3 Post by Compo » 28 Jul 2014 13:00

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: .BAT copy and paste with time taken

#4 Post by foxidrive » 29 Jul 2014 00:32

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.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: .BAT copy and paste with time taken

#5 Post by Squashman » 29 Jul 2014 09:00

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.

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: .BAT copy and paste with time taken

#6 Post by Compo » 29 Jul 2014 10:49

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: .BAT copy and paste with time taken

#7 Post by foxidrive » 29 Jul 2014 18:18

Compo wrote:The original question says
johnbird 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 :oops:


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

Post Reply