-1

I'm looking (if possible) for a check and copy batch script that I can run remotely to check multiple directories and copy the newest modified date.

To clarify: On the remote machine I'm looking at a potential five folders (that may or may not be there). I need the script to check the last modified date of two sub-folders (Desktop and Internet Favorites) of a user's potential 5 profiles, then pick the most recent modified date and copy the folders to another location

So pathway looks like:

"\\%asset%\c$\documents and settings\%username%\Desktop"
"\\%asset%\c$\documents and settings\%username%\Favorites"

To check the date and compare it with (potentially)

"\\%asset%\c$\documents and settings\%username%.temp\Desktop"
"\\%asset%\c$\documents and settings\%username%.temp\Favorites"

Or

"\\%asset%\c$\documents and settings\%username%.temp001\Desktop"
"\\%asset%\c$\documents and settings\%username%.temp001\Favorites"

Once it has found the sub-folders with the most recent modified date to copy (only the most recent) to:

"\\%asset%\c$\documents and settings\Backup"

I know I can get the check done on one location, but I don't know how to ask batch to run multiple checks and then to pick the most recent.

Is that actually possible or am I trying this in the wrong language? I've gotten every thing but the check written out and that's where I'm getting stuck...

Any help would be appreciated!

Andriy M
  • 76,112
  • 17
  • 94
  • 154
  • Need a clearer idea of what you are trying to do. For instance, We'll have to assume you have a list of ASSETS, and USERNAMES (but USERNAME has a special meaning - the CURRENT username) and what these "potential 5 profiles" are named - no suffix, .temp, .temp001 - presumably .temp002 and .temp002. Are you aware that if a subdirectory of one of these directories is changed, the date on the directory is NOT changed? Does that change your thinking? It IS possible to simply `XCOPY /D` from EACH of the 'potential 5' subdirectories and land up with the latest of all available versions. – Magoo Mar 23 '13 at 15:42
  • The downside would be that if a user changed say a shortcut and then copied an older version back, then the LATEST version of the shortcut would be the one after the original change...Beyond that - if you want the latest directory date (ignoring that a subdirectory may have changed) then we'd need to do heavy-duty date/time manipulation, and need to know your date-time format. – Magoo Mar 23 '13 at 15:48
  • I'm sure it can be done with batch, but as Peter Wright alludes to, date comparisons in batch are fragile and difficult. I think it would be better to look at Powershell. – Nate Hekman Mar 23 '13 at 17:06

1 Answers1

0

As I said in my comment, I think Powershell would be better suited to the task. But I did think of one approach that may work in batch without having to resort to textual date comparisons (which are difficult).

You may be able to use robocopy with its /copy:t option which copies timestamps. Imagine copying all three directories to one location, then doing a dir /b /od to list out this temporary directory sorted by date to find the most recent one, and copy that to your target.

I don't have time to test this theory out or give you real code, but hopefully it gives you an approach to try. Or convinces you to take a look at Powershell. :-)

Nate Hekman
  • 6,507
  • 27
  • 30