Jump to content

How tough would this be?


Recommended Posts

Here's what I would like to do, I want to overcome the MS "feature" that links the system clock to all files/folders on a machine. So, we just had a time change in the US, and all my files on the servers are now +1 hour, however all the SAME files on a USB key are still the same as before the time change since the usb key has no system clock. So, when I compare the files with Robocopy, you guessed it, every folder/file is seen different and a full sync must occur. I want to reset all the files on either the keys, or the servers, probably the servers since only 2 of them exist and I have 3 dozen keys. I found some apps that can do this, but you have to buy them, not happening and I want more control of this.

How can I do this in AutoIT? I know you can query a single file with FileGetTime, and you can also set with FileSetTime, the problem is I have to do this on 1000's of files and folders... I found a vb script:

Set objShell = _
  CreateObject("Shell.Application")

Set objFolder = _
  objShell.NameSpace("f:\")
Set colItems = objFolder.Items

For Each objItem In colItems
    objItem.ModifyDate  = _
      "01/01/2008 8:00:00 AM"
Next

But it won't do folders or recurse files/folders in sub-folders... so I know this is POSSIBLE, but I can't for the life of me figure this out.

Ideally I provide a path, and a plus or minus value, like -1, and the script goes and changes everything behind the scenes.

Any help would be greatly appreciated.

Link to comment
Share on other sites

Oh, and in PowerShell, I found this script that will update all files with a specific incremental time for the modified time, but it's also setting the date/time based on the $a variable... I just want to read all files/folders and increment X number of hours plus or minus... so close...!!!!

$a = Get-Date "2/13/2007 8:00 AM"

$b = Get-ChildItem "C:\Scripts"

foreach ($i in $b)
{
    $i.LastWriteTime = $a
    $a = $a.AddMinutes(1)   
}

$b
Link to comment
Share on other sites

@GregThompson...Try this with some a test folder with some files first...

#Include <File.au3>
#Include <Array.au3>
#Include <Date.au3>

$Folder=@ScriptDir & "\Change"
$FileList=_FileListToArray($Folder)
If @Error=1 Then
MsgBox (0,"","No Files\Folders Found.")
Exit

Else
;_ArrayDisplay($FileList,"$FileList")


For $x=1 to $FileList[0]


$t =  FileGetTime($Folder & "\" & $FileList[$x], 0)
$Old_Date=$t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]

$New_Date=StringStripWS(StringReplace(StringReplace(_DateAdd("h", 1, $Old_Date),"/",""),":",""),8)

;MsgBox(4096,"",$New_Date)
FileSetTime($Folder & "\" & $FileList[$x], $New_Date,0)

Next

EndIf
Link to comment
Share on other sites

@GregThompson...Try this with some a test folder with some files first...

#Include <File.au3>
#Include <Array.au3>
#Include <Date.au3>

$Folder=@ScriptDir & "\Change"
$FileList=_FileListToArray($Folder)
If @Error=1 Then
MsgBox (0,"","No Files\Folders Found.")
Exit

Else
;_ArrayDisplay($FileList,"$FileList")


For $x=1 to $FileList[0]


$t =  FileGetTime($Folder & "\" & $FileList[$x], 0)
$Old_Date=$t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]

$New_Date=StringStripWS(StringReplace(StringReplace(_DateAdd("h", 1, $Old_Date),"/",""),":",""),8)

;MsgBox(4096,"",$New_Date)
FileSetTime($Folder & "\" & $FileList[$x], $New_Date,0)

Next

EndIf

DJD, it works great, the only problem is that it doesn't recurse sub-directories... thanks though.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...