Page 1 of 1

Renaming files, using the date of creation to order them...

Posted: 06 Jan 2011 06:35
by mbgf23
Hello there,
Again needing your help and here I do not even know how to start my scrip :S
I have a large number of files (around 2000 in the same folder) with different names and no relation between those names, and I need to rename them like this
In a txt file I have the list of names like this:
-----Names.txt------
file1
file2
file4
fileOne
-----EndOfNames.txt---
(Note that the names are not correlative, so I can have "file1" and after that "file24" or "fileUnique", that is why I need to do it with this list.)
But I also need the script to rename in this way, to order the files by creation date like this, the "oldest" will have the name file1.pdf (I forgot to mention that all of them are pdf files, so the extension will be .pdf), the second created will have the name file2.pdf...and so on.
There is some way to do that? I hope so...
And thanks in advance for your help.
(Sorry for my english and do not hesitate to ask if more clarification is needed.)

Re: Renaming files, using the date of creation to order them

Posted: 06 Jan 2011 11:10
by ChickenSoup
Do they have to come from your names.txt file? or can this be generated on the fly from a DIR command?

Re: Renaming files, using the date of creation to order them

Posted: 06 Jan 2011 11:53
by aGerman
Well it's realy not "best practice" to do this in batch, but doable.
The DIR command is able to sort files by creation time (on NTFS formatted volumes). I agree with ChickenSoup, it's easier to work with DIR on the fly because the names in a textfile don't contain the creation time ...

Regards
aGerman

Re: Renaming files, using the date of creation to order them

Posted: 07 Jan 2011 08:01
by mbgf23
yes, unfortunately the names have to came from the txt file :(
In my scenario i know for sure that the first created has to have the first name in my list and so on...and to rename 2000 files on the fly will be crazy...that is why I am trying to make it in a batch.
Thank you very much aGerman and ChickemSoup for your reply!

Re: Renaming files, using the date of creation to order them

Posted: 07 Jan 2011 14:29
by aGerman
mbgf23 wrote:...and to rename 2000 files on the fly will be crazy...

:?: Arm ... WHY?

mbgf23 wrote:In my scenario i know for sure that the first created has to have the first name in my list and so on...

I don't get it. You have already sorted the files by date in your file?
Well then loop over the file using FOR /F and increment a variable that acts as new file name. Use a temporary folder to move the files in the first step to make sure you will never overwrite an existing file with the same name.

Regards
aGerman