ruffing has asked for the wisdom of the Perl Monks concerning the following question:

I'm able to modify the access time but not the creation date of the folder? I use utime to modify the modified date but haven't found any function for the creation date. Any suggestions or is this even possible?
  • Comment on How do you modify the creation date of a folder?

Replies are listed 'Best First'.
Re: How do you modify the creation date of a folder?
by HollyKing (Pilgrim) on Oct 03, 2001 at 20:22 UTC

    I don't know much about Perl yet as I'm still learning. However I do know quite a bit about the Win32 API. Try looking at CreateFile and SetFileTime. These two functions together will accomplish what you want to do.

    Owl looked at him, and wondered whether to push him off the tree; but, feeling that he could always do it afterwards, he tried once more to find out what they were talking about.

      I found the CreateFile function in Win32API but not the SetFileTime. Scott

        You can find information about SetFileTime at Microsoft's website.

        Owl looked at him, and wondered whether to push him off the tree; but, feeling that he could always do it afterwards, he tried once more to find out what they were talking about.

Re: How do you modify the creation date of a folder?
by davorg (Chancellor) on Oct 03, 2001 at 19:37 UTC

    Because the creation date is... er... the date the file was created (hence the name!)

    You can modify or access the file, so changing the mtime or atime makes sense, but you can't create the file again, so changing the ctime isn't possible.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you don't talk about Perl club."

      What happened was through copying a disk drive to another drive, the folders it created on the new drive to house the info from the other drive had an updated creation time. I'm looking to try to match the original time on the old drive with the time on the new drive. But if I can't modify the date of the new folders, I'll have to come up with an alternative solution. The reason being is that our perl scripts depend on the creation time of folders in a certain directory. Thanks for your help anyways. Scott
        The correct solution seems to be to change the perl scripts to not reily (solely) on the ctime of the folders, not to change the ctime of the folders.
        Thanks,
        James Mastros,
        Just Another Perl Initate

      ctime, in standard UNIX semantics, is not the creation time of the file. It is a timestamp updated whenever the file or directory's inode is updated (e.g. with chmod or chown, or when utime(2) is called on the file itself). It can be thought as a "change time" but definitely it is not the "creation time".

      As far as I know it cannot be altered without low level editing of the partition where the inode resides.

      So, ruffing, you're out of luck twice: once because ctime cannot be altered, twice because it is not the creation time. This also means that it's probably a good idea to follow theorbtwo's suggestion and change your Perl scripts: you're not relying on the creation time of the inode, but rather on the time it was last updated, which can be totally different.

      -- TMTOWTDI

Re: How do you modify the creation date of a folder?
by Anonymous Monk on Oct 03, 2001 at 20:43 UTC
    Which system are you using? If you are using UNIX you can "tar" up the files and you can have it keep the original creation date when you extract them. This will allow you to make a copy of the files with the same creation date.
Re: How do you modify the creation date of a folder?
by tune (Curate) on Oct 03, 2001 at 19:47 UTC
    Here's a nasty trick if you really want to do it:

    create a temporary folder (e.g. _tmp), and move every file into it, delete the old folder, and rename _tmp to the original name. Then you will have a creation time. Though you will be able to make it the current date only.

    --
    tune

      One solution I found was to update the system time of the computer to the date in the past I want the folder to be created on. Add the files to that folder and reset the date of the computer. That will allow me to make it more than just the current date. The downfall however is a lot of folder renaming ... and the side-effects of altering the computer's time and date.