Behavior of “?” is fishy when trying to rename all the files of current folder(thro' Batch Script) expecting that extension would be unchangedHow do I rename the extension for a bunch of files?batch script for pdflatex-makeindex-bibtex that works on current file in notepad++File renaming batch scriptWindows batch file renaming via reordering current nameHow to renaming a lot of folders with a Windows batch fileRenaming a Folder using Batch ScriptBatch file that moves all movies to a specific folder file needs renamedrename all files in a folder with batch fileRename all files in folder using batch or powershell run from batchBatch Script to Rename Files to “Raw.txt” in Subfolders
Why, even after his imprisonment, people keep calling Hannibal Lecter "Doctor"?
Is differentiation as a map discontinuous?
Are fuzzy sets appreciated by OR community?
Algorithm that generates orthogonal vectors: C++ implementation
Which lens has the same capability of lens mounted in Nikon P1000?
Averting Bathos
How 象【しょう】 ( ≈かたち、 すがた、ようす) and 象【ぞう】 (どうぶつ) got to be written with the same kanji?
Youtube not blocked by iptables
How do you use the interjection for snorting?
Why does this image of Jupiter look so strange?
There are 51 natural numbers between 1-100, proof that there are 2 numbers such that the difference between them equals to 5
Why does (inf + 0j)*1 evaluate to inf + nanj?
We are on WHV, my boyfriend was in a small collision, we are leaving in 2 weeks what happens if we don’t pay the damages?
What exactly did this mechanic sabotage on the American Airlines 737, and how dangerous was it?
How do pilots align the HUD with their eyeballs?
List of 1000 most common words across all languages
Align all symbols in a LaTeX equation
My manager quit. Should I agree to defer wage increase to accommodate budget concerns?
Is it impolite to ask for an in-flight catalogue with no intention of buying?
Why are there two fundamental laws of logic?
Is a Middle Name a Given Name?
Top off gas with old oil, is that bad?
What does ubuntu server show on display under normal operation?
Why does my browser attempt to download pages from http://clhs.lisp.se instead of viewing them normally?
Behavior of “?” is fishy when trying to rename all the files of current folder(thro' Batch Script) expecting that extension would be unchanged
How do I rename the extension for a bunch of files?batch script for pdflatex-makeindex-bibtex that works on current file in notepad++File renaming batch scriptWindows batch file renaming via reordering current nameHow to renaming a lot of folders with a Windows batch fileRenaming a Folder using Batch ScriptBatch file that moves all movies to a specific folder file needs renamedrename all files in a folder with batch fileRename all files in folder using batch or powershell run from batchBatch Script to Rename Files to “Raw.txt” in Subfolders
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have been scripting in Windows(7 64Bit) Batch engine for sometime now.
What I find really disappointing is the rename command when trying to rename all files in a folder and using "?" to keep the file extension unaltered.
Please look at the below set of commands:
@echo off
set /p filename="Desired File Name: "
rename *.* "%filename%.???"
This is supposed to keep the file extension as it is but, on the contrary, if I pass the filename as "MONEY 2016" it unexpectedly renames the files to "MONEY 2016.201", why is that ?
Also, as debugging step, I printed the filename right after getting it inputted from the user, it prints as it is with spaces, so it doesn't seem like space issue at all..
How to make this work as expected with a one-liner as short as possible ?
windows batch-file wildcard file-rename batch-rename
add a comment
|
I have been scripting in Windows(7 64Bit) Batch engine for sometime now.
What I find really disappointing is the rename command when trying to rename all files in a folder and using "?" to keep the file extension unaltered.
Please look at the below set of commands:
@echo off
set /p filename="Desired File Name: "
rename *.* "%filename%.???"
This is supposed to keep the file extension as it is but, on the contrary, if I pass the filename as "MONEY 2016" it unexpectedly renames the files to "MONEY 2016.201", why is that ?
Also, as debugging step, I printed the filename right after getting it inputted from the user, it prints as it is with spaces, so it doesn't seem like space issue at all..
How to make this work as expected with a one-liner as short as possible ?
windows batch-file wildcard file-rename batch-rename
You seem to be assuming that all extensions are three characters long, which is not generally the case. They could be any length at all. But let's assume for now that they are all 3 characters long in your particular folder. What are the original complete filenames (with extensions) in the folder (before renaming)?
– Klitos Kyriacou
Mar 28 at 17:57
3
AForloop is the way to go,For %%A In (*.*)Do If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul.
– Compo
Mar 28 at 18:08
@Klitos Kyriacou: The folder could contain files(with generally long names like those of Movies) of type video(with audio) and subtitles like MKV, AVI, MP4, SRT, SUB etc. But I want to write as generalised command/script as possible.
– Vicky Dev
Mar 28 at 20:33
@Compo: That worked well..
– Vicky Dev
Mar 28 at 20:34
1
It appears thatrenameconsiders.201segment as the destination extension and ignores the following.and anything after. Any name containing a.generates the duplicate error as the same destination name and extension is repeating i.e. nameMONEY 2016and extension.201. The name ofNewNameworks,New.Namedoes not.
– michael_heath
Mar 29 at 7:06
add a comment
|
I have been scripting in Windows(7 64Bit) Batch engine for sometime now.
What I find really disappointing is the rename command when trying to rename all files in a folder and using "?" to keep the file extension unaltered.
Please look at the below set of commands:
@echo off
set /p filename="Desired File Name: "
rename *.* "%filename%.???"
This is supposed to keep the file extension as it is but, on the contrary, if I pass the filename as "MONEY 2016" it unexpectedly renames the files to "MONEY 2016.201", why is that ?
Also, as debugging step, I printed the filename right after getting it inputted from the user, it prints as it is with spaces, so it doesn't seem like space issue at all..
How to make this work as expected with a one-liner as short as possible ?
windows batch-file wildcard file-rename batch-rename
I have been scripting in Windows(7 64Bit) Batch engine for sometime now.
What I find really disappointing is the rename command when trying to rename all files in a folder and using "?" to keep the file extension unaltered.
Please look at the below set of commands:
@echo off
set /p filename="Desired File Name: "
rename *.* "%filename%.???"
This is supposed to keep the file extension as it is but, on the contrary, if I pass the filename as "MONEY 2016" it unexpectedly renames the files to "MONEY 2016.201", why is that ?
Also, as debugging step, I printed the filename right after getting it inputted from the user, it prints as it is with spaces, so it doesn't seem like space issue at all..
How to make this work as expected with a one-liner as short as possible ?
windows batch-file wildcard file-rename batch-rename
windows batch-file wildcard file-rename batch-rename
asked Mar 28 at 17:47
Vicky DevVicky Dev
4907 silver badges26 bronze badges
4907 silver badges26 bronze badges
You seem to be assuming that all extensions are three characters long, which is not generally the case. They could be any length at all. But let's assume for now that they are all 3 characters long in your particular folder. What are the original complete filenames (with extensions) in the folder (before renaming)?
– Klitos Kyriacou
Mar 28 at 17:57
3
AForloop is the way to go,For %%A In (*.*)Do If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul.
– Compo
Mar 28 at 18:08
@Klitos Kyriacou: The folder could contain files(with generally long names like those of Movies) of type video(with audio) and subtitles like MKV, AVI, MP4, SRT, SUB etc. But I want to write as generalised command/script as possible.
– Vicky Dev
Mar 28 at 20:33
@Compo: That worked well..
– Vicky Dev
Mar 28 at 20:34
1
It appears thatrenameconsiders.201segment as the destination extension and ignores the following.and anything after. Any name containing a.generates the duplicate error as the same destination name and extension is repeating i.e. nameMONEY 2016and extension.201. The name ofNewNameworks,New.Namedoes not.
– michael_heath
Mar 29 at 7:06
add a comment
|
You seem to be assuming that all extensions are three characters long, which is not generally the case. They could be any length at all. But let's assume for now that they are all 3 characters long in your particular folder. What are the original complete filenames (with extensions) in the folder (before renaming)?
– Klitos Kyriacou
Mar 28 at 17:57
3
AForloop is the way to go,For %%A In (*.*)Do If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul.
– Compo
Mar 28 at 18:08
@Klitos Kyriacou: The folder could contain files(with generally long names like those of Movies) of type video(with audio) and subtitles like MKV, AVI, MP4, SRT, SUB etc. But I want to write as generalised command/script as possible.
– Vicky Dev
Mar 28 at 20:33
@Compo: That worked well..
– Vicky Dev
Mar 28 at 20:34
1
It appears thatrenameconsiders.201segment as the destination extension and ignores the following.and anything after. Any name containing a.generates the duplicate error as the same destination name and extension is repeating i.e. nameMONEY 2016and extension.201. The name ofNewNameworks,New.Namedoes not.
– michael_heath
Mar 29 at 7:06
You seem to be assuming that all extensions are three characters long, which is not generally the case. They could be any length at all. But let's assume for now that they are all 3 characters long in your particular folder. What are the original complete filenames (with extensions) in the folder (before renaming)?
– Klitos Kyriacou
Mar 28 at 17:57
You seem to be assuming that all extensions are three characters long, which is not generally the case. They could be any length at all. But let's assume for now that they are all 3 characters long in your particular folder. What are the original complete filenames (with extensions) in the folder (before renaming)?
– Klitos Kyriacou
Mar 28 at 17:57
3
3
A
For loop is the way to go, For %%A In (*.*)Do If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul.– Compo
Mar 28 at 18:08
A
For loop is the way to go, For %%A In (*.*)Do If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul.– Compo
Mar 28 at 18:08
@Klitos Kyriacou: The folder could contain files(with generally long names like those of Movies) of type video(with audio) and subtitles like MKV, AVI, MP4, SRT, SUB etc. But I want to write as generalised command/script as possible.
– Vicky Dev
Mar 28 at 20:33
@Klitos Kyriacou: The folder could contain files(with generally long names like those of Movies) of type video(with audio) and subtitles like MKV, AVI, MP4, SRT, SUB etc. But I want to write as generalised command/script as possible.
– Vicky Dev
Mar 28 at 20:33
@Compo: That worked well..
– Vicky Dev
Mar 28 at 20:34
@Compo: That worked well..
– Vicky Dev
Mar 28 at 20:34
1
1
It appears that
rename considers .201 segment as the destination extension and ignores the following . and anything after. Any name containing a . generates the duplicate error as the same destination name and extension is repeating i.e. name MONEY 2016 and extension .201. The name of NewName works, New.Name does not.– michael_heath
Mar 29 at 7:06
It appears that
rename considers .201 segment as the destination extension and ignores the following . and anything after. Any name containing a . generates the duplicate error as the same destination name and extension is repeating i.e. name MONEY 2016 and extension .201. The name of NewName works, New.Name does not.– michael_heath
Mar 29 at 7:06
add a comment
|
2 Answers
2
active
oldest
votes
Here's my comment as an answer.
I'd suggest a For loop as a simple method of performing this task:
@Set /P "filename=Desired File Name: "
@For %%A In (*.*)Do @If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul
Please note that this method does not perform any verification of the user input. They could enter nothing, or they may enter a filename which is invalid. I'll leave it to you to implement a verification process, should you feel it necessary.
While this works, it doesn't explain why the OP's attempt didn't. It worked for me when I tried it.
– Klitos Kyriacou
Mar 28 at 23:07
add a comment
|
You are changing the structure of original and new names. * certainly does not match ??? (this should be obvious). A rename command with the proper structure works well:
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 four.srt
28/03/2019 10:11 p. m. 7 one.mkv
28/03/2019 10:11 p. m. 7 three.avi
28/03/2019 10:11 p. m. 7 two.mp4
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
C:UsersAntonioTests> rename *.* NewName.*
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 NewName.avi
28/03/2019 10:11 p. m. 7 NewName.mkv
28/03/2019 10:11 p. m. 7 NewName.mp4
28/03/2019 10:11 p. m. 7 NewName.srt
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
But when I tryrename *.* %filename%.*as per what you suggested(expecting it will work same with variable substitution as well), it gives errorThe syntax of the command is incorrect.
– Vicky Dev
Mar 30 at 19:17
Well, if%filename%may contain spaces (you didn't mentioned this point, so I can only guess), then just enclose the new name between quotes as it appears in your original example:rename *.* "%filename%.*". My only point is that???and*does not match each other, so you must use the same pattern at both original and new names...
– Aacini
Mar 30 at 20:12
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403947%2fbehavior-of-is-fishy-when-trying-to-rename-all-the-files-of-current-foldert%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's my comment as an answer.
I'd suggest a For loop as a simple method of performing this task:
@Set /P "filename=Desired File Name: "
@For %%A In (*.*)Do @If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul
Please note that this method does not perform any verification of the user input. They could enter nothing, or they may enter a filename which is invalid. I'll leave it to you to implement a verification process, should you feel it necessary.
While this works, it doesn't explain why the OP's attempt didn't. It worked for me when I tried it.
– Klitos Kyriacou
Mar 28 at 23:07
add a comment
|
Here's my comment as an answer.
I'd suggest a For loop as a simple method of performing this task:
@Set /P "filename=Desired File Name: "
@For %%A In (*.*)Do @If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul
Please note that this method does not perform any verification of the user input. They could enter nothing, or they may enter a filename which is invalid. I'll leave it to you to implement a verification process, should you feel it necessary.
While this works, it doesn't explain why the OP's attempt didn't. It worked for me when I tried it.
– Klitos Kyriacou
Mar 28 at 23:07
add a comment
|
Here's my comment as an answer.
I'd suggest a For loop as a simple method of performing this task:
@Set /P "filename=Desired File Name: "
@For %%A In (*.*)Do @If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul
Please note that this method does not perform any verification of the user input. They could enter nothing, or they may enter a filename which is invalid. I'll leave it to you to implement a verification process, should you feel it necessary.
Here's my comment as an answer.
I'd suggest a For loop as a simple method of performing this task:
@Set /P "filename=Desired File Name: "
@For %%A In (*.*)Do @If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul
Please note that this method does not perform any verification of the user input. They could enter nothing, or they may enter a filename which is invalid. I'll leave it to you to implement a verification process, should you feel it necessary.
answered Mar 28 at 20:54
CompoCompo
19.6k3 gold badges11 silver badges27 bronze badges
19.6k3 gold badges11 silver badges27 bronze badges
While this works, it doesn't explain why the OP's attempt didn't. It worked for me when I tried it.
– Klitos Kyriacou
Mar 28 at 23:07
add a comment
|
While this works, it doesn't explain why the OP's attempt didn't. It worked for me when I tried it.
– Klitos Kyriacou
Mar 28 at 23:07
While this works, it doesn't explain why the OP's attempt didn't. It worked for me when I tried it.
– Klitos Kyriacou
Mar 28 at 23:07
While this works, it doesn't explain why the OP's attempt didn't. It worked for me when I tried it.
– Klitos Kyriacou
Mar 28 at 23:07
add a comment
|
You are changing the structure of original and new names. * certainly does not match ??? (this should be obvious). A rename command with the proper structure works well:
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 four.srt
28/03/2019 10:11 p. m. 7 one.mkv
28/03/2019 10:11 p. m. 7 three.avi
28/03/2019 10:11 p. m. 7 two.mp4
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
C:UsersAntonioTests> rename *.* NewName.*
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 NewName.avi
28/03/2019 10:11 p. m. 7 NewName.mkv
28/03/2019 10:11 p. m. 7 NewName.mp4
28/03/2019 10:11 p. m. 7 NewName.srt
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
But when I tryrename *.* %filename%.*as per what you suggested(expecting it will work same with variable substitution as well), it gives errorThe syntax of the command is incorrect.
– Vicky Dev
Mar 30 at 19:17
Well, if%filename%may contain spaces (you didn't mentioned this point, so I can only guess), then just enclose the new name between quotes as it appears in your original example:rename *.* "%filename%.*". My only point is that???and*does not match each other, so you must use the same pattern at both original and new names...
– Aacini
Mar 30 at 20:12
add a comment
|
You are changing the structure of original and new names. * certainly does not match ??? (this should be obvious). A rename command with the proper structure works well:
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 four.srt
28/03/2019 10:11 p. m. 7 one.mkv
28/03/2019 10:11 p. m. 7 three.avi
28/03/2019 10:11 p. m. 7 two.mp4
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
C:UsersAntonioTests> rename *.* NewName.*
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 NewName.avi
28/03/2019 10:11 p. m. 7 NewName.mkv
28/03/2019 10:11 p. m. 7 NewName.mp4
28/03/2019 10:11 p. m. 7 NewName.srt
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
But when I tryrename *.* %filename%.*as per what you suggested(expecting it will work same with variable substitution as well), it gives errorThe syntax of the command is incorrect.
– Vicky Dev
Mar 30 at 19:17
Well, if%filename%may contain spaces (you didn't mentioned this point, so I can only guess), then just enclose the new name between quotes as it appears in your original example:rename *.* "%filename%.*". My only point is that???and*does not match each other, so you must use the same pattern at both original and new names...
– Aacini
Mar 30 at 20:12
add a comment
|
You are changing the structure of original and new names. * certainly does not match ??? (this should be obvious). A rename command with the proper structure works well:
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 four.srt
28/03/2019 10:11 p. m. 7 one.mkv
28/03/2019 10:11 p. m. 7 three.avi
28/03/2019 10:11 p. m. 7 two.mp4
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
C:UsersAntonioTests> rename *.* NewName.*
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 NewName.avi
28/03/2019 10:11 p. m. 7 NewName.mkv
28/03/2019 10:11 p. m. 7 NewName.mp4
28/03/2019 10:11 p. m. 7 NewName.srt
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
You are changing the structure of original and new names. * certainly does not match ??? (this should be obvious). A rename command with the proper structure works well:
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 four.srt
28/03/2019 10:11 p. m. 7 one.mkv
28/03/2019 10:11 p. m. 7 three.avi
28/03/2019 10:11 p. m. 7 two.mp4
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
C:UsersAntonioTests> rename *.* NewName.*
C:UsersAntonioTests> dir
El volumen de la unidad C no tiene etiqueta.
El número de serie del volumen es: 0895-160E
Directorio de C:UsersAntonioTests
28/03/2019 10:12 p. m. <DIR> .
28/03/2019 10:12 p. m. <DIR> ..
28/03/2019 10:11 p. m. 7 NewName.avi
28/03/2019 10:11 p. m. 7 NewName.mkv
28/03/2019 10:11 p. m. 7 NewName.mp4
28/03/2019 10:11 p. m. 7 NewName.srt
4 archivos 28 bytes
2 dirs 391,521,251,328 bytes libres
answered Mar 29 at 4:17
AaciniAacini
54k9 gold badges57 silver badges83 bronze badges
54k9 gold badges57 silver badges83 bronze badges
But when I tryrename *.* %filename%.*as per what you suggested(expecting it will work same with variable substitution as well), it gives errorThe syntax of the command is incorrect.
– Vicky Dev
Mar 30 at 19:17
Well, if%filename%may contain spaces (you didn't mentioned this point, so I can only guess), then just enclose the new name between quotes as it appears in your original example:rename *.* "%filename%.*". My only point is that???and*does not match each other, so you must use the same pattern at both original and new names...
– Aacini
Mar 30 at 20:12
add a comment
|
But when I tryrename *.* %filename%.*as per what you suggested(expecting it will work same with variable substitution as well), it gives errorThe syntax of the command is incorrect.
– Vicky Dev
Mar 30 at 19:17
Well, if%filename%may contain spaces (you didn't mentioned this point, so I can only guess), then just enclose the new name between quotes as it appears in your original example:rename *.* "%filename%.*". My only point is that???and*does not match each other, so you must use the same pattern at both original and new names...
– Aacini
Mar 30 at 20:12
But when I try
rename *.* %filename%.* as per what you suggested(expecting it will work same with variable substitution as well), it gives error The syntax of the command is incorrect.– Vicky Dev
Mar 30 at 19:17
But when I try
rename *.* %filename%.* as per what you suggested(expecting it will work same with variable substitution as well), it gives error The syntax of the command is incorrect.– Vicky Dev
Mar 30 at 19:17
Well, if
%filename% may contain spaces (you didn't mentioned this point, so I can only guess), then just enclose the new name between quotes as it appears in your original example: rename *.* "%filename%.*". My only point is that ??? and * does not match each other, so you must use the same pattern at both original and new names...– Aacini
Mar 30 at 20:12
Well, if
%filename% may contain spaces (you didn't mentioned this point, so I can only guess), then just enclose the new name between quotes as it appears in your original example: rename *.* "%filename%.*". My only point is that ??? and * does not match each other, so you must use the same pattern at both original and new names...– Aacini
Mar 30 at 20:12
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55403947%2fbehavior-of-is-fishy-when-trying-to-rename-all-the-files-of-current-foldert%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You seem to be assuming that all extensions are three characters long, which is not generally the case. They could be any length at all. But let's assume for now that they are all 3 characters long in your particular folder. What are the original complete filenames (with extensions) in the folder (before renaming)?
– Klitos Kyriacou
Mar 28 at 17:57
3
A
Forloop is the way to go,For %%A In (*.*)Do If Not Exist "%filename%%%~xA" Ren "%%A" "%filename%%%~xA" 2>Nul.– Compo
Mar 28 at 18:08
@Klitos Kyriacou: The folder could contain files(with generally long names like those of Movies) of type video(with audio) and subtitles like MKV, AVI, MP4, SRT, SUB etc. But I want to write as generalised command/script as possible.
– Vicky Dev
Mar 28 at 20:33
@Compo: That worked well..
– Vicky Dev
Mar 28 at 20:34
1
It appears that
renameconsiders.201segment as the destination extension and ignores the following.and anything after. Any name containing a.generates the duplicate error as the same destination name and extension is repeating i.e. nameMONEY 2016and extension.201. The name ofNewNameworks,New.Namedoes not.– michael_heath
Mar 29 at 7:06