Rename all text files within a folder

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Rename all text files within a folder

Post by Michael Abrams »

Not likely, but I will ask anyway:

Is there a simple way to rename all files within a folder?

I have a Folder1

In this folder are 50 files with extension .txt.txt (brilliant client, eh)

I want to remove the second .txt from all of the files.

If it is complicated (or cannot be done) I will assign my assistant to rename them manually.

And they do need to be renamed. Lots of import specs and macros etc based on .txt

Thanks for any ideas.

User avatar
stuck
UraniumLounger
Posts: 6933
Joined: 25 Jan 2010, 09:09
Location: up North (but it's not that grim)

Re: Rename all text files within a folder

Post by stuck »

Searching for 'batch file rename' gives lots of hits. This one might help you:
https://www.howtogeek.com/111859/how-to ... ple-files/

Ken

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

Excellent - I think this one will work:

ren *.txt.txt *.???

I can't wait to try it !

Thank you Ken !

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

OK - I have no idea about this. :sad:

Maybe Windows7 Enterprise is different than this example.

The quickest way to open a Command Prompt window at your desired location is to first open the folder in File Explorer. From the “File” menu, point to “Open command prompt,” and then select “Open command prompt.”

I am in this folder: C:\Users\AbramsM\Downloads\New folder

There is no option Open Command prompt in the File menu.
If I open the Command prompt from the Start menu:
C:\Users\AbramsM>

I think once I get the command prompt, the rest will be easy.

Any thoughts?

Thank you so much....

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

Re: Rename all text files within a folder

Post by HansV »

In the command prompt window, type

cd C:\Users\AbramsM\Downloads\New folder

and press Enter.
Regards,
Hans

User avatar
Leif
Administrator
Posts: 7249
Joined: 16 Jan 2010, 08:21
Location: UK/France

Re: Rename all text files within a folder

Post by Leif »

Michael Abrams wrote:
27 Aug 2021, 13:51
I am in this folder: C:\Users\AbramsM\Downloads\New folder
If you are in File Explorer,then (in theory*) you should be able to open a command prompt quite easily:
Open Command Window Here | Tutorials

* untested
Leif.

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

I probably learned that 20 years - maybe the first or second thing I ever learned. Darn.....

Since the ren command can address extensions, you can also use it to change the extensions of multiple files at once. Say, for example, you had a selection of .txt files that you wanted to turn into .html files. You could use the following command along with the * wildcard (which basically tells Windows that text of any length should be considered a match):
Example:
ren *.txt *.html


So using that prompt, I have tried many different variations of the rename.
ren *.txt.txt *.???

ren *.txt.txt *.txt

Looks correct, but does nothing.

User avatar
Leif
Administrator
Posts: 7249
Joined: 16 Jan 2010, 08:21
Location: UK/France

Re: Rename all text files within a folder

Post by Leif »

Double check you are in the correct folder by typing:
dir
which should list the contents.
Leif.

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

Amazingly, I am in the correct folder.

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

sample filename

rpt_brw_11m.seq_m8_20210820_w_s.txt.txt

need to be:

rpt_brw_11m.seq_m8_20210820_w_s.txt

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

Re: Rename all text files within a folder

Post by HansV »

I can confirm that ren *.txt.txt *.txt doesn't work.
Try this:

ren *.txt.txt ????????????????????????????????????????????????????.txt

Include enough ? to cover the longest file name.
Regards,
Hans

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

It only updated the first one.
"A duplicate filename exists or the file cannot be found"

there are 50 files named: (the only difference is the "m8" - each file is a different "M")
rpt_brw_11m.seq_m8_20210820_w_s.txt.txt

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

Actually, I need to work on this.

The code actually produced this: ace_rpt_brw_11m.txt
AND
it added an additional .txt to all the other files !

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

Re: Rename all text files within a folder

Post by HansV »

Do a search using your favorite search engine for batch rename utility and you'll find lots of free ones.
Regards,
Hans

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

Looks like that's the best solution !

But I am now challenged and will try my best to solve it.

Thank you and have a great weekend all!

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

My lovely IT department "allowed" me to use Powershell.
I am so close, but keep getting an error ( I am sure I have a dot dash bracket space too many/too little.

Here is the line I am using - do you see the error? ( folder is here: C:\Users\AbramsM\Downloads\New folder)

PS C:\Users\AbramsM\Downloads\New Folder>"dir | rename-item -NewName {$_.name -replace ".txt.txt",".txt"}"

The error attached:
You do not have the required permissions to view the files attached to this post.

User avatar
Leif
Administrator
Posts: 7249
Joined: 16 Jan 2010, 08:21
Location: UK/France

Re: Rename all text files within a folder

Post by Leif »

For what it is worth...

ren *.txt *.

appears to remove the last ".txt" from any appropriate filename (but if you have "filename.txt" it will end up as just "filename")
Leif.

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

Leif - that is AMAZING

One hit of the ENTER key updated 200 filenames in 1 second.

I will try to make my future posts more clear so I do not cause 15 replies.

Thank you Leif and everyone here for being here.

Michael Abrams
4StarLounger
Posts: 495
Joined: 10 Feb 2010, 17:32

Re: Rename all text files within a folder

Post by Michael Abrams »

And by the way - is ren *.txt *. a good example of Occam's Razor? OY!

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

Re: Rename all text files within a folder

Post by John Gray »

Michael Abrams wrote:
27 Aug 2021, 20:00
And by the way - is ren *.txt *. a good example of Occam's Razor? OY!
Well, not really!
Occam's Razor refers to alternative explanations of a phenomenon, where "the most straightforward / simplest is probably the best".
Your ren statement is simply one which works!
John Gray

“The only difference between reality and fiction is that fiction needs to be credible.” - Mark Twain.