Rename all text files within a folder

User avatar
Michael Abrams
4StarLounger
Posts: 573
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
Panoramic Lounger
Posts: 8125
Joined: 25 Jan 2010, 09:09
Location: retirement

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

User avatar
Michael Abrams
4StarLounger
Posts: 573
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 !

User avatar
Michael Abrams
4StarLounger
Posts: 573
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: 78236
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.
Best wishes,
Hans

User avatar
Leif
Administrator
Posts: 7193
Joined: 15 Jan 2010, 22:52
Location: Middle of England

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

User avatar
Michael Abrams
4StarLounger
Posts: 573
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: 7193
Joined: 15 Jan 2010, 22:52
Location: Middle of England

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

User avatar
Michael Abrams
4StarLounger
Posts: 573
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.

User avatar
Michael Abrams
4StarLounger
Posts: 573
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: 78236
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.
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
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

User avatar
Michael Abrams
4StarLounger
Posts: 573
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: 78236
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.
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
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!

User avatar
Michael Abrams
4StarLounger
Posts: 573
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: 7193
Joined: 15 Jan 2010, 22:52
Location: Middle of England

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

User avatar
Michael Abrams
4StarLounger
Posts: 573
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.

User avatar
Michael Abrams
4StarLounger
Posts: 573
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: 5401
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

Venison is quiet deer, and quite dear.