Batch renaming files

GeekGirlInFurs
Lounger
Posts: 43
Joined: 01 Feb 2016, 08:43

Batch renaming files

Post by GeekGirlInFurs »

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

User avatar
HansV
Administrator
Posts: 77998
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Batch renaming files

Post by HansV »

Try a rename utility such as Denis Kozlov's Renamer
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: Batch renaming files

Post by Rudi »

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
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
John Gray
PlatinumLounger
Posts: 5383
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Batch renaming files

Post by John Gray »

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!

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
* 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!)
John Gray

Venison is quiet deer, and quite dear.

GeekGirlInFurs
Lounger
Posts: 43
Joined: 01 Feb 2016, 08:43

Re: Batch renaming files

Post by GeekGirlInFurs »

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! :clapping: :cheers: :thankyou:

User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Batch renaming files

Post by Argus »

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.
Byelingual    When you speak two languages but start losing vocabulary in both of them.

User avatar
John Gray
PlatinumLounger
Posts: 5383
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Batch renaming files

Post by John Gray »

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.
Probably you missed the bit about removing ECHO on the second run, to get the REName to actually happen?! [As Argus says]

I did test it!
John Gray

Venison is quiet deer, and quite dear.

User avatar
viking33
PlatinumLounger
Posts: 5685
Joined: 24 Jan 2010, 19:16
Location: Cape Cod, Massachusetts,USA

Re: Batch renaming files

Post by viking33 »

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! :clapping: :cheers: :thankyou:
I have beeen staying out of this Thread for a couple of reasons.
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:
Also a good assist from my Swedish buddy, Argus.
BOB
:massachusetts: :usa:
______________________________________

If I agreed with you we'd both be wrong.

User avatar
Argus
GoldLounger
Posts: 3081
Joined: 24 Jan 2010, 19:07

Re: Batch renaming files

Post by Argus »

Not much we can do, Bob. :laugh:
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.