#1 2007-09-29 20:15

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

Folder Date and Time Stamps

I have been unable to change Date Stamp of folders.
1. I have ReNamer options set to treat folders as files,
2. I sort by folder column, parent folder names last,
3.  SetFileTime is last operation of script and of preset.

My goal is to restore Date Stamps to folders after renaming files within them.  Every folder has a hidden file named 'folder.jpg' that has not been renamed (still has original Date Stamp) that I will use as my source for restoring folder date.  (For my purpose I need to be able to sort folders by name or by date, so placing date in file name is not feasible).

To keep it simple in this example, I am testing with a single empty folder using fixed dates.  What am I doing wrong??  If folder contains files, their dates get changed properly but folder date remains unchanged.   (my only experience using pascal is with ReNamer so I make dumb mistakes, but I am stuck with this one)

var
  CreatedDate, ModifiedDate: TDateTime;
  
begin
  CreatedDate := EncodeDate(2003, 01, 02);
  ModifiedDate := EncodeDate(2006, 04, 05);
  SetFileTimeCreated(FilePath, CreatedDate);
  SetFileTimeModified(FilePath, ModifiedDate);
end.

ReNamer is such a powerful, friendly, useful, well supported and thought out ongoing program.  It is well appreciated.  I was truly afraid when you lost your data!  I am so glad it was recovered, I hope you did as well recovering all other important data.

Thanks,
Fathom

Offline

#2 2007-09-30 21:39

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Folder Date and Time Stamps

SetFileTimeCreated and SetFileTimeModified were not meant for folders wink

Windows doesn't really let programmers change folder dates easily.... and it is simply impossible on Win 9x.

I made some adjustments, and now these 2 function will also set dates for folders (only on Win 2K, XP, Vista).

Try from here: ReNamerBeta.zip

NOTE: These functions will be applied on PREVIEW, and not on RENAME.
Dates that are displayed in ReNamer will not be updated until you add those files/folders again.

Offline

#3 2007-10-01 21:24

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

Re: Folder Date and Time Stamps

Thanks so much, I have wanted to get this working for a long time.  I had misread an earlier post and thought the 'SetFileTime' functions worked with folders as well 'FileTime' functions.

It performed well on > 400 folders.  It really helps in this instance to be able to sort these folders by name, or their earliest file date. 
Anyway, this what I ended up with...

// Changes folders to same 'Date Modified' as that of a specific file within the folders //
// "Add folders as files" and "column sort order" settings are not required //
  
var
 Date: TDateTime;
 currentfolder: WideString;

begin
 if WideExtractFileName(FilePath) = 'folder.jpg' then Date := FileTimeModified(FilePath);
 CurrentFolder := WideExtractFileDir(FilePath);
 SetFileTimeModified(CurrentFolder, Date);
end.

It's is always interesting to watch for new developments with ReNamer and other den4b creations.
Scott

Offline

#4 2007-10-02 10:30

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Folder Date and Time Stamps

Your code is a bit UNSAFE, because for every item in the renaming list, it will set "SOME" date to the parent folder, even when the Date parameter has not yet been initialized. You only need to set the date ONCE, and ONLY if the Date is initialized by the "folder.jpg" file.

Something like that would be much better:

 if WideExtractFileName(FilePath) = 'folder.jpg' then
 begin
   Date := FileTimeModified(FilePath);
   CurrentFolder := WideExtractFileDir(FilePath);
   SetFileTimeModified(CurrentFolder, Date);
 end;

Offline

#5 2007-10-03 00:15

Fathom
Member
From: Boulder, CO USA
Registered: 2007-05-10
Posts: 29

Re: Folder Date and Time Stamps

Duh, I kept thinking there was something obvious missing when I looked at it, the long "if" line did not help.
As mentioned in first post "I make dumb mistakes", thank you for the correction.

Scott

Offline

#6 2007-10-04 12:50

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Folder Date and Time Stamps

There is no such thing as "dumb" mistakes for the person who is just staring to use PascalScript wink

Offline

Board footer

Powered by FluxBB