Page 1 of 1
Renaming files with Date Modified as Prefix

Posted:
Fri Dec 02, 2016 11:19 am
by vmax77
Hi
Objective - Rename files that are not folders with the "Date Modified" as the prefix to the file.
Current rule setup
Rule 1 - If Kind is Folder then Run rules on Folder content
Rule 2
If Kind is not Folder then Rename with pattern <date> <filename>.<extension>
Problem
FIrst time the renaming happens its fine, but the after second modification of the file, the first modified date is part of the file name. So file name ends up as <Date 2><Date1> <filename>.<extension>.
What I want to achieve
Check if the filename's first 10 chars(YYYY-MM-DD) is Date Modified.
If Date Modified matches then Do Nothing
If Date Modified does not match, check the first 10 chars form a date (not sure what is the elegant way to do this)
If first 10 chars are date, truncate the current date and rename with Date modified prefix.
If first 10 chars are NOT date, just prefix the with Date modified prefix.
Re: Renaming files with Date Modified as Prefix

Posted:
Fri Dec 02, 2016 12:51 pm
by Mr_Noodle
What version of Hazel are you running? I did add some extra loop detection in version 4 but if you are running an older version then this might still be an issue.
Regardless, to do what you want, you want to use match patterns. Search for it in the help. You can match on a date using that.
Re: Renaming files with Date Modified as Prefix

Posted:
Fri Dec 02, 2016 6:24 pm
by vmax77
Mr_Noodle wrote:What version of Hazel are you running? I did add some extra loop detection in version 4 but if you are running an older version then this might still be an issue.
Regardless, to do what you want, you want to use match patterns. Search for it in the help. You can match on a date using that.
HI
I am using V4.0.6
Re: Renaming files with Date Modified as Prefix

Posted:
Sat Dec 03, 2016 4:26 am
by vmax77
vmax77 wrote:Mr_Noodle wrote:What version of Hazel are you running? I did add some extra loop detection in version 4 but if you are running an older version then this might still be an issue.
Regardless, to do what you want, you want to use match patterns. Search for it in the help. You can match on a date using that.
HI
I am using V4.0.6
First I couldn't get it to filter for files with names starting with date. Also I couldn't use the match patterns to detect for existing date in the front of the filename. Even if that did happen, I can't seem to find any way to strip the date in front of the name to be replaced with new date.
Re: Renaming files with Date Modified as Prefix

Posted:
Mon Dec 05, 2016 12:24 pm
by Mr_Noodle
Can you post what you have so far?
Re: Renaming files with Date Modified as Prefix

Posted:
Wed Dec 07, 2016 7:16 pm
by vmax77
Mr_Noodle wrote:Can you post what you have so far?
This is what I have
http://imgur.com/a/UI7i2
Re: Renaming files with Date Modified as Prefix

Posted:
Thu Dec 08, 2016 12:24 pm
by Mr_Noodle
Note that when you use "Name matches/does not match", the pattern has to account for everything in the name. In your case, you are only matching names that only consist of a date. If there is any more text after the date, it won't match. If you don't care what occurs after the date, drag in the "anything" token to match anything (or nothing).
Re: Renaming files with Date Modified as Prefix

Posted:
Sun Dec 11, 2016 11:11 pm
by vmax77
Mr_Noodle wrote:Note that when you use "Name matches/does not match", the pattern has to account for everything in the name. In your case, you are only matching names that only consist of a date. If there is any more text after the date, it won't match. If you don't care what occurs after the date, drag in the "anything" token to match anything (or nothing).
Aha! That helps, thank you very much.
I still seem to struggling to replace the matched date. Or to trim the first characters (date part) of the filename, so the name is only the filename excluding the date modified
Re: Renaming files with Date Modified as Prefix

Posted:
Mon Dec 12, 2016 4:21 am
by vmax77
vmax77 wrote:Mr_Noodle wrote:Note that when you use "Name matches/does not match", the pattern has to account for everything in the name. In your case, you are only matching names that only consist of a date. If there is any more text after the date, it won't match. If you don't care what occurs after the date, drag in the "anything" token to match anything (or nothing).
Aha! That helps, thank you very much.
I still seem to struggling to replace the matched date. Or to trim the first characters (date part) of the filename, so the name is only the filename excluding the date modified
Update:
Managed to cobble an Applescript together to trim the existing date prefix to the filename.
- Code: Select all
set file_name to name of theFile
set datemod to modification date of theFile
if file_name does not start with (current date) then
set trim_name to text 11 thru -1 of file_name
set file_name to datemod & " " & trim_name
set new_name to file_name
end if
This is what I have now
http://i63.tinypic.com/1y61c0.jpg
Re: Renaming files with Date Modified as Prefix

Posted:
Mon Dec 12, 2016 12:40 pm
by Mr_Noodle
You shouldn't need a script for that. In your pattern, use a custom attribute to match everything after the date. Then use that custom attribute in the rename pattern.