Hello. I hope this is an appropriate place for this kind of question.
I have folders that contain a large number of files with files names in this format:
20170108_192400.txt
I would like to rename these to be easier to read quickly, while retaining sortability by filename, so that I end up with this:
2017-01-08_192400.txt
Is it possible to do this as a batch process? I am comfortable using a command line if necessary. I believe I once did this kind of thing back in the DOS days, when filenames were restricted to 8 characters plus a 3-character extension. But the few test runs I've done on longer filenames using a command line have mostly just thrown errors.
How would you go about doing this?
Thank you!
GGIF
Batch renaming files
-
- Administrator
- Posts: 78594
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Batch renaming files
I agree with Han's suggestion. I've used ReNamer for years and will swear by it!
A great product from Denis!
PS: You can download the portable version if its a once off task. No installation necessary
A great product from Denis!
PS: You can download the portable version if its a once off task. No installation necessary
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- PlatinumLounger
- Posts: 5415
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: Batch renaming files
Hello GGIF
Yes, it would be quite easy to do this via a BATch file - but I'm just off to work, so will try it later, if that's OK with you!
LATER...
Here you are!
* Run it once to ensure that it does what you expect (the DIR will show the current state of the folder).
* Remove the capitalised ECHO from the second-last line, then run it again ONCE - the DIR will show the new state of the folder.
(I don't do any checking that the rename has already happened!)
Yes, it would be quite easy to do this via a BATch file - but I'm just off to work, so will try it later, if that's OK with you!
LATER...
Here you are!
Code: Select all
@echo off
:: call this something like RENAMER.BAT
:: and place it in the folder containing all the .TXT files
:: this assume that ALL required files are of the form
:: yyyymmdd_hhmmss.txt
:: 01234567
setlocal
set log=%~n0.log
if exist %log% del %log%
for /f %%a in ('dir /b *.txt') do call :process %%a
echo.>>%log%
echo Directory List of folder...>>%log%
dir /b >>%log%
start "" notepad %log%
endlocal
goto :eof
:process the filename
set old=%1
set new=%old:~0,4%-%old:~4,2%-%old:~6%
echo Renaming %old% to %new% >> %log%
ECHO ren %old% %new%
goto :eof
* Remove the capitalised ECHO from the second-last line, then run it again ONCE - the DIR will show the new state of the folder.
(I don't do any checking that the rename has already happened!)
John Gray
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
-
- Lounger
- Posts: 47
- Joined: 01 Feb 2016, 08:43
Re: Batch renaming files
Hello all. Thank you for the replies!
John Gray -- thank you especially for the effort in writing that batch file. However, it's not working for me. The log files indicate what would be the proper output, but the file names aren't changing.
As it turns out, the Renamer program was just what I was looking for, and did just what I needed.
Thank you!
![ThankYou :thankyou:](./images/smilies/thankyou.gif)
John Gray -- thank you especially for the effort in writing that batch file. However, it's not working for me. The log files indicate what would be the proper output, but the file names aren't changing.
As it turns out, the Renamer program was just what I was looking for, and did just what I needed.
Thank you!
![Clapping :clapping:](./images/smilies/clapping.gif)
![Cheers :cheers:](./images/smilies/cheers.gif)
![ThankYou :thankyou:](./images/smilies/thankyou.gif)
-
- GoldLounger
- Posts: 3081
- Joined: 24 Jan 2010, 19:07
Re: Batch renaming files
It worked like a charm here, and created log files.
Placed in the folder.
Remember to edit (remove capitalised ECHO) and run it again, once, as John said.
Placed in the folder.
Remember to edit (remove capitalised ECHO) and run it again, once, as John said.
Byelingual When you speak two languages but start losing vocabulary in both of them.
-
- PlatinumLounger
- Posts: 5415
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: Batch renaming files
Probably you missed the bit about removing ECHO on the second run, to get the REName to actually happen?! [As Argus says]GeekGirlInFurs wrote: John Gray -- thank you especially for the effort in writing that batch file. However, it's not working for me. The log files indicate what would be the proper output, but the file names aren't changing.
I did test it!
John Gray
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
"(or one of the team)" - how your hospital appointment letter indicates that you won't be seeing the Consultant...
-
- PlatinumLounger
- Posts: 5685
- Joined: 24 Jan 2010, 19:16
- Location: Cape Cod, Massachusetts,USA
Re: Batch renaming files
I have beeen staying out of this Thread for a couple of reasons.GeekGirlInFurs wrote:Hello all. Thank you for the replies!
John Gray -- thank you especially for the effort in writing that batch file. However, it's not working for me. The log files indicate what would be the proper output, but the file names aren't changing.
As it turns out, the Renamer program was just what I was looking for, and did just what I needed.
Thank you!![]()
![]()
1. I don't know very much about Batch files. i thought they were a a way to make scrambled eggs?
2. I knew that the Lounge expert on Batch files, John Gray, would pop in andgive the correct answer. As he has done!
![ThumbUp :thumbup:](./images/smilies/thumbup.gif)
Also a good assist from my Swedish buddy, Argus.
BOB
![USA :usa:](./images/smilies/USA.gif)
______________________________________
If I agreed with you we'd both be wrong.
![Massachusetts :massachusetts:](./images/smilies/Massachusetts.gif)
![USA :usa:](./images/smilies/USA.gif)
______________________________________
If I agreed with you we'd both be wrong.
-
- GoldLounger
- Posts: 3081
- Joined: 24 Jan 2010, 19:07
Re: Batch renaming files
Not much we can do, Bob. ![Laugh :laugh:](./images/smilies/laugh.gif)
Quick Admins had already mentioned a (flexible) tool or two, with UI, and with a batch file master in the Lounge it was only a matter of minutes before a complete solution.
![Laugh :laugh:](./images/smilies/laugh.gif)
Quick Admins had already mentioned a (flexible) tool or two, with UI, and with a batch file master in the Lounge it was only a matter of minutes before a complete solution.
Byelingual When you speak two languages but start losing vocabulary in both of them.