Rename files based on Age ?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
CookieMonster

Rename files based on Age ?

Post by CookieMonster »

Can you rename files specific criteria, based on the files age ?

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Rename files based on Age ?

Post by TheQwerty »

Please be more specific about what you're trying to do.

CookieMonster

Re: Rename files based on Age ?

Post by CookieMonster »

I have a huge list of files, some of those files were created, nine months ago, others the past 30 days. I want to batch rename all the files, but give the older files a different file name, then the newer files.

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Rename files based on Age ?

Post by highend »

No, that's absolutely impossible.
Reason: Scripting language is agnostic to logic (and tends to be very vague / unspecific).
Please use a different file manager (hint: it should lack a scripting language).
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Rename files based on Age ?

Post by TheQwerty »

CookieMonster wrote:I have a huge list of files, some of those files were created, nine months ago, others the past 30 days. I want to batch rename all the files, but give the older files a different file name, then the newer files.
Search for the files you want to give one name and then rename those files.
Search for the files you want to give a different name, and rename those.
Repeat until complete.

CookieMonster

Re: Rename files based on Age ?

Post by CookieMonster »

I can't do a batch Job make it quicker, especially for future use. I tend to run into this quite often with a large school of files. The rename feature in XY is great, if I could have that added flexibility it would be even nicer.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Rename files based on Age ?

Post by TheQwerty »

Maybe you should hire a programmer to help with all your odd "time-saving" requests?

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Rename files based on Age ?

Post by Stefan »

CookieMonster wrote:Can you rename files specific criteria, based on the files age ?
This could be done by a script.
If you can't write a script, at least write the wanted logic in English words, like:

for each file in [select folder]
    var = get modifcation date
       if (today minus var == more than 90 days) then do this:
       if (today minus var == less than 90 days) then do this:
next file


Perhaps somebody get an idea and the time to aid you....

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Rename files based on Age ?

Post by j_c_hallgren »

TheQwerty wrote:Maybe you should hire a programmer to help with all your odd "time-saving" requests?
Or at least someone to help translate the requests into something that can be easily understood here -and- to avoid the apparent lack of doing reading, research and training based on other posts made here..

Note to CookieMonster: I have no idea what you situation and/or education and/or skill level is -but- what I'm now seeing is that it seems you're beginning to get on the nerves of some of our other regulars here by the lack of trying to do things yourself and repeatedly asking for step-by-step help...and that can only be harmful to you in the future because you'll wear out your welcome and get less aid, ok? So please try and work out some things yourself between postings...I'm NOT trying to be critical because there may be a language issue as well, but just giving a hint on how not to get yourself in the "doghouse", ok?
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

CookieMonster

Re: Rename files based on Age ?

Post by CookieMonster »

Stefan wrote:
CookieMonster wrote:Can you rename files specific criteria, based on the files age ?
This could be done by a script.
If you can't write a script, at least write the wanted logic in English words, like:

for each file in [select folder]
    var = get modifcation date
       if (today minus var == more than 90 days) then do this:
       if (today minus var == less than 90 days) then do this:
next file


Perhaps somebody get an idea and the time to aid you....
I think it's better to write how the script should work in plain English rather then in code speak :) In code speak the basics of the condition above is generally what I want :)

Do you have to set the "select folder" as a variable ?

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Rename files based on Age ?

Post by Stefan »

CookieMonster wrote:Do you have to set the "select folder" as a variable ?
Not necessary. Depends on what you want to do.


The script could be written to do exactly what you want. You just have to define first what that would be.




For example, here we just work on the current folder and do a loop over every item:

Code: Select all

// loop through the whole current list

    // go to top to first item:
   //sel 1; 

   //loop till end of list:
   while ( "<curitem>" != "" )
   {


        //do something:
        msg "<curitem>",1;
   


  
       //select next item in list to work on:
       sel "+1";
   }



Now the same with code to check the date difference:

Code: Select all



// loop through the whole list
   //sel 1; // go to top first, if you want.
   
   
   while ( "<curitem>" != "" )
   {

        /*
               See Help > Variables
               <date>      current date
               <datem>     modified date of the current list item
               <datec>     created date of the current list item
               <datea>     accessed date of the current list item
        */

        //do an diff on current item against current date:

        //datediff(date1, [date2=now], [interval=d])
        $DateDiff = datediff("<datem>");


        //check if DateDiff is greater than 90 (days here):
        if($DateDiff > 90){

                    //if yes, do this:
                    msg "OLD ONE FOUND<crlf 2><curitem> - <datem> - $DateDiff days old.",1;

        }else{

                    //if not, do this here:
                    msg "This is too young: <curitem> - <datem> - $DateDiff days old.",1;

        }
        
     sel "+1";
    }


Next you have to decide what to do with older or younger items...
And to add some safety net and error handling, and maybe more checking, e.g. skip items which are folders, or such.

If you don't understood what this does, you may want to read the first posts from the scripting forum and the help file about scripting.

CookieMonster

Re: Rename files based on Age ?

Post by CookieMonster »

Stefan, I can read the script, but like some people when it comes to speaking a language, I have problems putting the language together :) :(

Reading the scripts does help to make sense.

My goal was the script would rename the older files a set name that I would be prompt with, then the younger files a set name, once again I would be prompt with, and finally the newest files, once again I would be prompt with. Regardless if there are (50) old files, those old file could be renamed as such; the first file would be <acme2>, each sequential file would be <acme3,4,5,6,7.....> if there is a letter in place such as; <acmeA7> then it would be <acmeB8,C9,D9 etc....> if it were to reach the end of the alphabet then a letter would be replaced with a number starting at 0.

j_c_hallgren
XY Blog Master
Posts: 5824
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Rename files based on Age ?

Post by j_c_hallgren »

CookieMonster wrote:Stefan, I can read the script, but like some people when it comes to speaking a language, I have problems putting the language together :) :(

Reading the scripts does help to make sense.
And it's my guess that until you begin to show some serious efforts on your own to learn scripting, you will soon find yourself not getting any assistance here because it appears you've constantly giving new specs and asking for changes to what has been provided...not trying to be harsh but just warning you that you're beginning to irritate some of those who've really spent a lot of time trying to help you already, ok?
My goal was the script would rename the older files a set name that I would be prompt with, then the younger files a set name, once again I would be prompt with, and finally the newest files, once again I would be prompt with. Regardless if there are (50) old files, those old file could be renamed as such; the first file would be <acme2>, each sequential file would be <acme3,4,5,6,7.....> if there is a letter in place such as; <acmeA7> then it would be <acmeB8,C9,D9 etc....> if it were to reach the end of the alphabet then a letter would be replaced with a number starting at 0.
See..here's yet another case of a revison to what you want to do...
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Rename files based on Age ?

Post by Stefan »

j_c_hallgren wrote:
CookieMonster wrote:
And it's my guess that until you begin to show some serious efforts on your own to learn scripting,
Not everybody have to become a coder, OK?
It should be enough if the user can just execute a script (that's why I suggest often simplifying scripting steps)

Even looking up the help to modify existing scripts can be over some not into that logical thinking.
Remember, this is a forum about a File Manager, we are not a scripting board.
So please everybody, be nice and helpfully, or go reading another thread you could aiding more useful, OK?
My goal was the script would rename the older files a set name that I would be prompt with, then the younger files a set name, once again I would be prompt with, and finally the newest files, once again I would be prompt with. Regardless if there are (50) old files, those old file could be renamed as such;
Huh :shock:
But it would be from much help if youanybody could better format there postings.
Just use a few more line breaks and break your prose into shorter steb-by-step explanations.
I am not in the mood to even read such a mess of a word stream :whistle:

the first file would be <acme2>, each sequential file would be <acme3,4,5,6,7.....>
if there is a letter in place such as; <acmeA7> then it would be <acmeB8,C9,D9 etc....>
if it were to reach the end of the alphabet then a letter would be replaced with a number starting at 0.
OK, sometimes it would nevertheless be better to learn scripting :lol: , because that request it out of my interest to code such script right now.
I have showing you the basics how to separate files based on date, but that renaming algorithm is a completely different thing :naughty: :D

CookieMonster

Re: Rename files based on Age ?

Post by CookieMonster »

I guess being a Cobol programmer can make some 'different', different equal to :twisted:
Huh :shock:
But it would be from much help if youanybody could better format there postings.
Just use a few more line breaks and break your prose into shorter steb-by-step explanations.
I am not in the mood to even read such a mess of a word stream :whistle:
Well anyhow, considering I don't have a solid grasp of the XY syntax. One could assume that a condition could check for an age criteria for a group of files, then the next group of younger files, then finally the youngest files which is what I've been leaning towards this whole time.

Post Reply