Jump to content

Change a folder's date


Recommended Posts

I use _Date_Time_SetFileTime to change the timestamps of files but it does not work on folders. Any other ideas to set the date of a folder?

Thanks!

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

  • Moderators

llewxam,

Why are you using the UDF? :mellow:

FileSetTime has always worked for me on both files and folders. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

JohnOne,

Delighted to have been of service. Wading through MSDN is something to be avoided at all costs. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

llewxam,

Why are you using the UDF? :mellow:

FileSetTime has always worked for me on both files and folders. :)

M23

I love you man, I need you on speed dial! :)

OK, for the purposes of setting the timestamp on a folder what you posted is perfect, and I thank you as always! I have been working on a huge update to my Sync tool and as part of it I decided that I wanted to have the option to preserve the original file's create, modify, and access timestamps. I wrote a couple functions based off the UDF because that was how I wrote my original function to compare 2 file's info:

Func _CompareFileTimeEx($hSource, $hDestination, $iMethod)
    ;Parameters ....:       $hSource -      Full path to the first file
    ;                       $hDestination - Full path to the second file
    ;                       $iMethod -      0   The date and time the file was created
    ;                                       1   The date and time the file was accessed
    ;                                       2   The date and time the file was modified
    ;Return values .:                       -1  First file time is earlier than second file time
    ;                                       0   First file time is equal to second file time
    ;                                       1   First file time is later than second file time
    ;Author ........:       Ian Maxwell (llewxam @ AutoIt forum)
    Local $hCurrent[2] = [$hSource, $hDestination], $tPointer[2] = ["", ""]
    For $iPointerCount = 0 To 1
        $hFile = _WinAPI_CreateFile($hCurrent[$iPointerCount], 2)
        $aTime = _Date_Time_GetFileTime($hFile)
        _WinAPI_CloseHandle($hFile)
        $aDate = _Date_Time_FileTimeToStr($aTime[$iMethod])
        $tFile = _Date_Time_EncodeFileTime(StringMid($aDate, 1, 2), StringMid($aDate, 4, 2), StringMid($aDate, 7, 4), StringMid($aDate, 12, 2), StringMid($aDate, 15, 2), StringMid($aDate, 18, 2))
        $aDOS = _Date_Time_FileTimeToDOSDateTime(DllStructGetPtr($tFile))
        $tFileTime = _Date_Time_DOSDateTimeToFileTime("0x" & Hex($aDOS[0], 4), "0x" & Hex($aDOS[1], 4))
        $tPointer[$iPointerCount] = DllStructGetPtr($tFileTime)
    Next
    Return _Date_Time_CompareFileTime($tPointer[0], $tPointer[1])
EndFunc   ;==>_CompareFileTimeEx

Using some of that code, I came up with this:

Func _RestoreDate($hSource, $hDestination)
    ;Author ........:       Ian Maxwell (llewxam @ AutoIt forum)
    $hFile = _WinAPI_CreateFile($hSource, 2)
    $aTime = _Date_Time_GetFileTime($hFile)
    _WinAPI_CloseHandle($hFile)
    $aCreateDate = _Date_Time_FileTimeToStr($aTime[0])
    $aAccessDate = _Date_Time_FileTimeToStr($aTime[1])
    $aModifyDate = _Date_Time_FileTimeToStr($aTime[2])
    $tCreateFile = _Date_Time_EncodeFileTime(StringMid($aCreateDate, 1, 2), StringMid($aCreateDate, 4, 2), StringMid($aCreateDate, 7, 4), StringMid($aCreateDate, 12, 2), StringMid($aCreateDate, 15, 2), StringMid($aCreateDate, 18, 2))
    $tAccessFile = _Date_Time_EncodeFileTime(StringMid($aAccessDate, 1, 2), StringMid($aAccessDate, 4, 2), StringMid($aAccessDate, 7, 4), StringMid($aAccessDate, 12, 2), StringMid($aAccessDate, 15, 2), StringMid($aAccessDate, 18, 2))
    $tModifyFile = _Date_Time_EncodeFileTime(StringMid($aModifyDate, 1, 2), StringMid($aModifyDate, 4, 2), StringMid($aModifyDate, 7, 4), StringMid($aModifyDate, 12, 2), StringMid($aModifyDate, 15, 2), StringMid($aModifyDate, 18, 2))
    $pCreateFile = DllStructGetPtr($tCreateFile)
    $pAccessFile = DllStructGetPtr($tAccessFile)
    $pModifyFile = DllStructGetPtr($tModifyFile)
    $hFile = _WinAPI_CreateFile($hDestination, 2)
    _Date_Time_SetFileTime($hFile, $pCreateFile, $pAccessFile, $pModifyFile)
    _WinAPI_CloseHandle($hFile)
EndFunc   ;==>_RestoreDate

I don't know how I missed FileGetTime and FileSetTime before, they seem to do just what I want, so I will have to spend a little time putting some new functions together and comparing them in terms of time and abilities, based on your suggestions.

Again, thanks as always!

Ian

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
Link to comment
Share on other sites

  • Moderators

llewxam,

I love you man

Careful now, she-who-must-be-obeyed will get all annoyed! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

llewxam,

Careful now, she-who-must-be-obeyed will get all annoyed! :)

M23

:mellow:

HAHAHAHA!!!!

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.
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...