Rename all text files within a folder
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Rename all text files within a folder
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.
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.
-
- Panoramic Lounger
- Posts: 8191
- Joined: 25 Jan 2010, 09:09
- Location: retirement
Re: Rename all text files within a folder
Searching for 'batch file rename' gives lots of hits. This one might help you:
https://www.howtogeek.com/111859/how-to ... ple-files/
Ken
https://www.howtogeek.com/111859/how-to ... ple-files/
Ken
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
Excellent - I think this one will work:
ren *.txt.txt *.???
I can't wait to try it !
Thank you Ken !
ren *.txt.txt *.???
I can't wait to try it !
Thank you Ken !
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
OK - I have no idea about this.
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....
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....
-
- Administrator
- Posts: 78625
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Rename all text files within a folder
In the command prompt window, type
cd C:\Users\AbramsM\Downloads\New folder
and press Enter.
cd C:\Users\AbramsM\Downloads\New folder
and press Enter.
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 7218
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
Re: Rename all text files within a folder
If you are in File Explorer,then (in theory*) you should be able to open a command prompt quite easily:Michael Abrams wrote: ↑27 Aug 2021, 13:51I am in this folder: C:\Users\AbramsM\Downloads\New folder
Open Command Window Here | Tutorials
* untested
Leif
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
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.
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.
-
- Administrator
- Posts: 7218
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
Re: Rename all text files within a folder
Double check you are in the correct folder by typing:
dir
which should list the contents.
dir
which should list the contents.
Leif
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
Amazingly, I am in the correct folder.
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
sample filename
rpt_brw_11m.seq_m8_20210820_w_s.txt.txt
need to be:
rpt_brw_11m.seq_m8_20210820_w_s.txt
rpt_brw_11m.seq_m8_20210820_w_s.txt.txt
need to be:
rpt_brw_11m.seq_m8_20210820_w_s.txt
-
- Administrator
- Posts: 78625
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Rename all text files within a folder
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.
Try this:
ren *.txt.txt ????????????????????????????????????????????????????.txt
Include enough ? to cover the longest file name.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
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
"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
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
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 !
The code actually produced this: ace_rpt_brw_11m.txt
AND
it added an additional .txt to all the other files !
-
- Administrator
- Posts: 78625
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Rename all text files within a folder
Do a search using your favorite search engine for batch rename utility and you'll find lots of free ones.
Best wishes,
Hans
Hans
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
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!
But I am now challenged and will try my best to solve it.
Thank you and have a great weekend all!
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
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:
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.
-
- Administrator
- Posts: 7218
- Joined: 15 Jan 2010, 22:52
- Location: Middle of England
Re: Rename all text files within a folder
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")
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
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
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.
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.
-
- 4StarLounger
- Posts: 579
- Joined: 10 Feb 2010, 17:32
Re: Rename all text files within a folder
And by the way - is ren *.txt *. a good example of Occam's Razor? OY!
-
- PlatinumLounger
- Posts: 5420
- Joined: 24 Jan 2010, 08:33
- Location: A cathedral city in England
Re: Rename all text files within a folder
Well, not really!Michael Abrams wrote: ↑27 Aug 2021, 20:00And by the way - is ren *.txt *. a good example of Occam's Razor? OY!
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
"(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...