Jump to content


Photo

How to timestamp clone files and folders or whole disk ?


  • Please log in to reply
10 replies to this topic

#1 awannaknow

awannaknow
  • Members
  • 369 posts

Posted 06 May 2012 - 03:10 PM

Hi Everybody,
Cannot get it right : Copy anything (files and folders or a whole disk) from where they are to where you want to copy them.
Keep it identical whether it's RASINDOC or/and Timestamp.

In the below code, that I cannot make working correctly, it's timestamps Created, Modified, Accessed (all of them) for all files and all folders.
I did manage to copy source to destination correctly, but I cannot get all timestamps in destination as they are in source.
Need a little push push to get back on track (may be a big one as I don't know how wrong I 'm . . .)
AHK_L 1.0.48.5 and XP SP3 Pro:
Source= "be carefull"
Dest= "be carefull"
Loop, %Source%\*.*, 1, 1 ;Loop thru whole selection
     {
;______________Progress Bar_______________

    GuiControl,, Progress, %A_Index% ; display progression in progress bar
;______________Progress Bar_______________
            SplitPath, Source, SourceFolderName ; Extract only the folder name from its full path.
            StringReplace, DestPath, A_LoopFileFullPath, %Source%, %Dest% ; Replace source with destination part of the loop full path
                  IfExist, %DestPath% ; if destination files/folders exist just need to set Modified Created Accessed TimeStamps
              {
                  FileGetTime, Mtime, %Dest%, M
                  if Mtime !=%A_LoopFileTimeModified%
                         FileSetTime, A_LoopFileTimeModified, %Dest%, M, 1

                     FileGetTime, Ctime, %Dest%, C
                      if Ctime !=%A_LoopFileTimeCreated%
                              FileSetTime, A_LoopFileTimeCreated, %Dest%, C, 1

                   FileGetTime, Atime, %Dest%, A
                   if Atime!=%A_LoopFileTimeAccessed%
                         FileSetTime, A_LoopFileTimeAccessed, %Dest%, A, 1
              }
                   else ; Always copy if target file doesn't yet exist.
     {
                  IfNotInString,A_LoopFileAttrib,D ;if it's not a directory. If it's a file
                  FileCopy, %A_LoopFileFullPath%, %DestPath% ; Copy with overwrite=no
                  else ;Then, according to the IfNotInString above : if it's a directory. If it's not a file
                  FileCopyDir, %Source%, %Dest%\%SourceFolderName% ;0 (default): Do not overwrite existing files.
     }
                       FileSetTime, %A_LoopFileTimeModified%, %Dest%\%SourceFolderName%, M, 1, 0
                       FileSetTime, %A_LoopFileTimeCreated%, %Dest%\%SourceFolderName%, C, 1, 0
                       FileSetTime, %A_LoopFileTimeAccessed%, %Dest%\%SourceFolderName%, A, 1, 0
                     }
Eventually, I also didn't get how to code the progress bar.
Edit : I deleted irrelevant code to make it easier to read.

#2 awannaknow

awannaknow
  • Members
  • 369 posts

Posted 10 May 2012 - 07:55 AM

up,
As I spent around 3 weeks on it without finding a solution, I don't feel like to letting it go, so I re-up. With a little chance someone more knowledgable may post one line or two that'll help me to finish this one.
Thanks in advance.

#3 CodeKiller

CodeKiller
  • Members
  • 2066 posts

Posted 10 May 2012 - 12:35 PM

First time :

Progress R0-1000 P0, SubText, MainText, WinTitle, FontName
Then each time you want to make the bar progress :

Prog += 50
Progress P%Prog%, SubText, MainText, WinTitle, FontName

The easiest way is to not use the Rx-y parameter so you can make progress %.
Example :
MaxFiles := 123
CurrentFile := 5 ; This number will be change in the loop, like CurrentFile := A_Index
Done := CurrentFile  / MaxFiles  * 100
Progress P%Done%, SubText, MainText, WinTitle, FontName


#4 JSLover

JSLover
  • Members
  • 920 posts

Posted 10 May 2012 - 12:38 PM

I already have a "clone.ahk" file, that I use...mostly, right now, it only copies timestamps, it doesn't attempt to do a more through "clone" yet...but the goal for it is, once used, the source & dest should be indistinguishable from each other...but, as I said, it's not finished & only does timestamps...& it doesn't have a progress bar (I know how to write a progress bar, but that means I'd need to copy 1 file at a time, so I can show a progress bar, instead of using the built-in FileCopyDir).

My method is just to FileCopyDir the entire thing, then to go back thru & set all the timestamps from the source onto the dest, if you don't, some of the dir timestamps can get clobbered when new files are added/copied later.

I can put it online, but it's not anywhere near where I want it to be...

#5 awannaknow

awannaknow
  • Members
  • 369 posts

Posted 10 May 2012 - 09:23 PM

Thank you CodeKiller, I'll spend time on it to understand and apply.
I hope someone will post some help about my main problem.
All the best mate.

Hi JSLover,
I see that your code needs 2 passes to complete the task, it might be way too slow for, let say a whole disk.
But it may shows me tracks to follow as I'm stalled and cannot go any further : my mind dried out ...
Thank you for your answer.

#6 awannaknow

awannaknow
  • Members
  • 369 posts

Posted 14 May 2012 - 02:24 PM

2nd up,
I re-up hoping some knowledgable members could help with this :

Copy anything (files and folders or a whole disk) from where they are to where you want to copy them.
Keep it identical whether it's RASINDOC or/and Timestamp.

Eventually, I also didn't get how to code the progress bar.

Will I ever "get it" oneday ? ? ?

#7 Guests

  • Guests

Posted 14 May 2012 - 02:31 PM

Why not use <!-- m -->https://en.wikipedia.org/wiki/Robocopy<!-- m --> or better why do you need AutoHotkey to do it and why would you care about a progressbar (other then keeping you informed that is busy for which you can use other less intrusive methods)

#8 JSLover

JSLover
  • Members
  • 920 posts

Posted 14 May 2012 - 02:38 PM

This didn't make that much sense the 1st time you posted it...

Keep it identical whether it's RASINDOC or/and Timestamp.

...what's a "RASINDOC"?...I've got an idea what you mean, but you could just say that instead of "RASINDOC".

Also, as I said, I have a clone.ahk...& (currently) "my code" don't really do "2 passes"...it does FileCopyDir on the entire set (so that could be considered "pass 1", but it's not my code making a pass, it's AutoHotkey/the OS doing the copy)...then, I actually start "my pass" (pass 1 or 2?) over the files, copying the timestamps. You really do need this 2-step process or the dir's timestamps will NOT be correct. My code could EASILY be altered to copy the RASINDOC (lol, just say "attributes"), since it's already copying timestamps 1-at-a-time.

Progress bars, in general, aren't hard, but tying it in with a FileCopyDir makes it hard...I'd probably, like I said, have to ditch FileCopyDir, in favor of copying it myself...or using some DllCall file copy function, so I can get a "callback" on each new file. FileCopyDir will copy it all, but it never tells me when a new file is getting copied...it just freezes the script until the copying is done. However, it would be easy to add a progress bar for the timestamp/attribute-setting pass.

#9 awannaknow

awannaknow
  • Members
  • 369 posts

Posted 14 May 2012 - 08:48 PM

Hi Guest,
I know that there is some softs that can do it out there, I've heard of robocopy before but was not sure it can do timestamps and attributes.
I stopped scipting for a long time (few months) and suddenly I felt the need to come back.
It happened that I also forgot much of the small pieces of knowledge I had such a dificulty to learn.
I decided to do it with AHK, because at first glance I thought it'ld not be out of my reach to do it.
Big mistake ! ! !
And now I spent so much time on it that I would not let it go and asked for a solution/help/road to be shown, as I'm still not sure if it's difficult to do or not.
After all it is just a trivial need and an almost everyday task to copy file(s).
And asking to get an exact, timestamp/attib,copy might not be so difficult to get.
That's why as of now I'm still not sure if it is difficult or not.
The answer might be : it depends of your own AHK scripting level, right?
>why would you care about a progressbar (other then keeping you informed that is busy for which you can use other less intrusive methods)
Because I thought of making a small GUI showing . . . well, progress . . .
When a big file is processed it looks like it's frozen, a progress bar could help to refrain to stop everything.
For this too I didn't thought it could be difficult to make one, as I never played with it before.
>you can use other less intrusive methods
like a messagebox with "finished" on it or someting like that ?
Anyway, I'll be happy if someone knows how to do it and how difficult it is.

Hi JSLover,
Well your right "attributes" is what I should have called 'em. It comes as Rashindoc instead . . .
Actually I try with timestamps.
>You really do need this 2-step process or the dir's timestamps will NOT be correct.
Maybe it's why I cannot get correct results. I didn't find a way to control what happens during the copy.
Your code could put me back on track and help me to go a little bit further, if I can understand it.
Someone may have scripted a faster way to do it.
Because for example for a 300Gb disk it is usually pretty lenghty, if it has to be 2 passes it might be way too long.
Progress bar is the icing on the cake, which seems very difficult to do according to both of you . . ., it was just a dream, sort of . . .

Thanks to both of you gentlemen, I may complete this one, after all.

If any readers knows how to help on this one, don't hesitate to post.

#10 JSLover

JSLover
  • Members
  • 920 posts

Posted 20 May 2012 - 09:19 PM

Sorry, awannaknow, I didn't mean to leave you hanging...& I did see the "bump" you posted today (that you now deleted, I guess) (& your PM {it's OK, PM's don't bother me}).

Yes, I did see your "double reply"...but I didn't really know how to respond...before I said "I can put it online, but it's not anywhere near where I want it to be..."...but I don't think I ever got a definitive "yes, please post it".

I will post it now...

Clone.ahk
Keep in mind that it has its quirks, be VERY careful when you use it. I'm posting the code as-is, though I may update it with more features later...it does NOT copy Attributes yet (but this should be simple to add) -- or should I say -- it does not TRY to copy attributes, they may possibly be copied from the FileCopyDir, but I have not verified/tested that.

Also, note, with the current code, you can't do...

clone.ahk C:\ D:\
...you must do...

clone.ahk C:\Dir D:\Dir
...or...

clone.ahk C:\ D:\Dir
...right now, the Destination has to be a (non-existent) directory (or file), since the code tries to delete the Dest (with a Confirmation), to prepare for the copying. I hope to get rid of this limitation, so that you can do a simple clone.ahk C:\ D:\. As I said, the code is no where near where I want it to be, but it has helped me, even in its primitive state.

Be careful...& report anything you notice.

#11 awannaknow

awannaknow
  • Members
  • 369 posts

Posted 21 May 2012 - 09:22 AM

Thank a lot JSLover,

You're right, I deleted the "double reply" as I sent you a PM it has no more use.

I will try to understand your code so I may come up with something closer to what I want to do.
It's so frustrating to get stuck each time I'm supposed to create someting easy to do.
It pretty immediately shows my limits.

Thanks too for your code explanations.

But at the same time I love when I can do something that's working, maybe is it why I can't stop smashing my head on the AHK wall again.
AHK, . . . I love you . . .
:oops: