Cut a part from a filename (windows batch)











up vote
1
down vote

favorite












I got files named like this:



cam1(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam2(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam3(word1 word2 wordN) (24-04-2012 00-11-13).mpg


Need to cut (word1 word2 word3) and replace spaces with _
Renamed files expected:



cam1_(24-04-2012_00-11-13).mpg
cam2_(24-04-2012_00-11-13).mpg
cam3_(24-04-2012_00-11-13).mpg


In the first brackets could be different number of "word". Timestamp is always the same.










share|improve this question




















  • 2




    is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nested For /F loops, or lots of %FOO:search=replace% in case the number of possible different words is small, but it would be definitely more ugly :)
    – mihi
    Apr 25 '12 at 17:20















up vote
1
down vote

favorite












I got files named like this:



cam1(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam2(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam3(word1 word2 wordN) (24-04-2012 00-11-13).mpg


Need to cut (word1 word2 word3) and replace spaces with _
Renamed files expected:



cam1_(24-04-2012_00-11-13).mpg
cam2_(24-04-2012_00-11-13).mpg
cam3_(24-04-2012_00-11-13).mpg


In the first brackets could be different number of "word". Timestamp is always the same.










share|improve this question




















  • 2




    is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nested For /F loops, or lots of %FOO:search=replace% in case the number of possible different words is small, but it would be definitely more ugly :)
    – mihi
    Apr 25 '12 at 17:20













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I got files named like this:



cam1(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam2(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam3(word1 word2 wordN) (24-04-2012 00-11-13).mpg


Need to cut (word1 word2 word3) and replace spaces with _
Renamed files expected:



cam1_(24-04-2012_00-11-13).mpg
cam2_(24-04-2012_00-11-13).mpg
cam3_(24-04-2012_00-11-13).mpg


In the first brackets could be different number of "word". Timestamp is always the same.










share|improve this question















I got files named like this:



cam1(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam2(word1 word2 wordN) (24-04-2012 00-11-13).mpg
cam3(word1 word2 wordN) (24-04-2012 00-11-13).mpg


Need to cut (word1 word2 word3) and replace spaces with _
Renamed files expected:



cam1_(24-04-2012_00-11-13).mpg
cam2_(24-04-2012_00-11-13).mpg
cam3_(24-04-2012_00-11-13).mpg


In the first brackets could be different number of "word". Timestamp is always the same.







windows batch-file batch-rename






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 5 '14 at 18:42









Hennes

58.7k792141




58.7k792141










asked Apr 25 '12 at 16:22









Igor

612




612








  • 2




    is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nested For /F loops, or lots of %FOO:search=replace% in case the number of possible different words is small, but it would be definitely more ugly :)
    – mihi
    Apr 25 '12 at 17:20














  • 2




    is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nested For /F loops, or lots of %FOO:search=replace% in case the number of possible different words is small, but it would be definitely more ugly :)
    – mihi
    Apr 25 '12 at 17:20








2




2




is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nested For /F loops, or lots of %FOO:search=replace% in case the number of possible different words is small, but it would be definitely more ugly :)
– mihi
Apr 25 '12 at 17:20




is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nested For /F loops, or lots of %FOO:search=replace% in case the number of possible different words is small, but it would be definitely more ugly :)
– mihi
Apr 25 '12 at 17:20










3 Answers
3






active

oldest

votes

















up vote
0
down vote













Add this code to a batchfile.



For /f "tokens=1-3 delims=(" %%a in ('dir *.mpg /b') do call :DoRename "%%a" "%%b" "%%c"

Goto :eof
:DoRename
Set SrcFile=%1(%2(%3
Set SrcFile=%srcfile:"=%

Set DestFile=%1 (%3
Set DestFile=%DestFile:"=%
Set DestFile=%DestFile: =_%

Rename "%SrcFile%" "%DestFile%"





share|improve this answer























  • ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename.
    – Igor
    Apr 25 '12 at 19:34












  • I didn't realize that the words were different all the time. I modified the script so it should work now.
    – ZEDA-NL
    Apr 25 '12 at 21:01


















up vote
0
down vote













I've used Bulk Rename Utility for just this sort of thing. It allows you remove, edit, replace or add numbers to filenames easily. And it does batch files. I use it all the time for renaming photos and video clips as well as mp3 files.






share|improve this answer























  • I need it to run it automatically from scheduler,
    – Igor
    Apr 25 '12 at 16:34










  • BRU has some very basic command line options, but is not well suited to being run from a scheduler.
    – JonathanDavidArndt
    Jan 6 at 3:33


















up vote
0
down vote













[Edit] as suggested by Scott



If you can do a little scripting, I recommend autohotkey
You can use a simple regexmatch()
To do your need full



Here is a sample code



Filelist=
Loop, C:Data*.mpg ;Assuming your files in data folder
Filelist = %Filelist%%A_LoopFileFullPath%`n
Loop, parse, filelist, `n
{
Renamed := Regrxreplace(A_Loopfield, "(w.+)s", "_")
Filemove, %A_LoopField%, %Renamed%
}


*Test it for few files



Regards
SDK.






share|improve this answer























  • Can you give an example of how something like this could be done with AutoHotkey?  Please do not respond in comments; edit your answer to make it clearer and more complete.
    – Scott
    Nov 20 at 4:09











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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',
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/3.0/"u003ecc by-sa 3.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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f416785%2fcut-a-part-from-a-filename-windows-batch%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Add this code to a batchfile.



For /f "tokens=1-3 delims=(" %%a in ('dir *.mpg /b') do call :DoRename "%%a" "%%b" "%%c"

Goto :eof
:DoRename
Set SrcFile=%1(%2(%3
Set SrcFile=%srcfile:"=%

Set DestFile=%1 (%3
Set DestFile=%DestFile:"=%
Set DestFile=%DestFile: =_%

Rename "%SrcFile%" "%DestFile%"





share|improve this answer























  • ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename.
    – Igor
    Apr 25 '12 at 19:34












  • I didn't realize that the words were different all the time. I modified the script so it should work now.
    – ZEDA-NL
    Apr 25 '12 at 21:01















up vote
0
down vote













Add this code to a batchfile.



For /f "tokens=1-3 delims=(" %%a in ('dir *.mpg /b') do call :DoRename "%%a" "%%b" "%%c"

Goto :eof
:DoRename
Set SrcFile=%1(%2(%3
Set SrcFile=%srcfile:"=%

Set DestFile=%1 (%3
Set DestFile=%DestFile:"=%
Set DestFile=%DestFile: =_%

Rename "%SrcFile%" "%DestFile%"





share|improve this answer























  • ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename.
    – Igor
    Apr 25 '12 at 19:34












  • I didn't realize that the words were different all the time. I modified the script so it should work now.
    – ZEDA-NL
    Apr 25 '12 at 21:01













up vote
0
down vote










up vote
0
down vote









Add this code to a batchfile.



For /f "tokens=1-3 delims=(" %%a in ('dir *.mpg /b') do call :DoRename "%%a" "%%b" "%%c"

Goto :eof
:DoRename
Set SrcFile=%1(%2(%3
Set SrcFile=%srcfile:"=%

Set DestFile=%1 (%3
Set DestFile=%DestFile:"=%
Set DestFile=%DestFile: =_%

Rename "%SrcFile%" "%DestFile%"





share|improve this answer














Add this code to a batchfile.



For /f "tokens=1-3 delims=(" %%a in ('dir *.mpg /b') do call :DoRename "%%a" "%%b" "%%c"

Goto :eof
:DoRename
Set SrcFile=%1(%2(%3
Set SrcFile=%srcfile:"=%

Set DestFile=%1 (%3
Set DestFile=%DestFile:"=%
Set DestFile=%DestFile: =_%

Rename "%SrcFile%" "%DestFile%"






share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 25 '12 at 21:00

























answered Apr 25 '12 at 18:25









ZEDA-NL

393210




393210












  • ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename.
    – Igor
    Apr 25 '12 at 19:34












  • I didn't realize that the words were different all the time. I modified the script so it should work now.
    – ZEDA-NL
    Apr 25 '12 at 21:01


















  • ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename.
    – Igor
    Apr 25 '12 at 19:34












  • I didn't realize that the words were different all the time. I modified the script so it should work now.
    – ZEDA-NL
    Apr 25 '12 at 21:01
















ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename.
– Igor
Apr 25 '12 at 19:34






ZEDA-NL, your script does replace space with _ , however I also need to remove (word1 word2 etc). Those words could be different like (description of event 15) or (this is test). I need to remove that part completely from the filename.
– Igor
Apr 25 '12 at 19:34














I didn't realize that the words were different all the time. I modified the script so it should work now.
– ZEDA-NL
Apr 25 '12 at 21:01




I didn't realize that the words were different all the time. I modified the script so it should work now.
– ZEDA-NL
Apr 25 '12 at 21:01












up vote
0
down vote













I've used Bulk Rename Utility for just this sort of thing. It allows you remove, edit, replace or add numbers to filenames easily. And it does batch files. I use it all the time for renaming photos and video clips as well as mp3 files.






share|improve this answer























  • I need it to run it automatically from scheduler,
    – Igor
    Apr 25 '12 at 16:34










  • BRU has some very basic command line options, but is not well suited to being run from a scheduler.
    – JonathanDavidArndt
    Jan 6 at 3:33















up vote
0
down vote













I've used Bulk Rename Utility for just this sort of thing. It allows you remove, edit, replace or add numbers to filenames easily. And it does batch files. I use it all the time for renaming photos and video clips as well as mp3 files.






share|improve this answer























  • I need it to run it automatically from scheduler,
    – Igor
    Apr 25 '12 at 16:34










  • BRU has some very basic command line options, but is not well suited to being run from a scheduler.
    – JonathanDavidArndt
    Jan 6 at 3:33













up vote
0
down vote










up vote
0
down vote









I've used Bulk Rename Utility for just this sort of thing. It allows you remove, edit, replace or add numbers to filenames easily. And it does batch files. I use it all the time for renaming photos and video clips as well as mp3 files.






share|improve this answer














I've used Bulk Rename Utility for just this sort of thing. It allows you remove, edit, replace or add numbers to filenames easily. And it does batch files. I use it all the time for renaming photos and video clips as well as mp3 files.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 4 '14 at 14:41









Cristian Ciupitu

4,0892540




4,0892540










answered Apr 25 '12 at 16:28









djmadscribbler

32136




32136












  • I need it to run it automatically from scheduler,
    – Igor
    Apr 25 '12 at 16:34










  • BRU has some very basic command line options, but is not well suited to being run from a scheduler.
    – JonathanDavidArndt
    Jan 6 at 3:33


















  • I need it to run it automatically from scheduler,
    – Igor
    Apr 25 '12 at 16:34










  • BRU has some very basic command line options, but is not well suited to being run from a scheduler.
    – JonathanDavidArndt
    Jan 6 at 3:33
















I need it to run it automatically from scheduler,
– Igor
Apr 25 '12 at 16:34




I need it to run it automatically from scheduler,
– Igor
Apr 25 '12 at 16:34












BRU has some very basic command line options, but is not well suited to being run from a scheduler.
– JonathanDavidArndt
Jan 6 at 3:33




BRU has some very basic command line options, but is not well suited to being run from a scheduler.
– JonathanDavidArndt
Jan 6 at 3:33










up vote
0
down vote













[Edit] as suggested by Scott



If you can do a little scripting, I recommend autohotkey
You can use a simple regexmatch()
To do your need full



Here is a sample code



Filelist=
Loop, C:Data*.mpg ;Assuming your files in data folder
Filelist = %Filelist%%A_LoopFileFullPath%`n
Loop, parse, filelist, `n
{
Renamed := Regrxreplace(A_Loopfield, "(w.+)s", "_")
Filemove, %A_LoopField%, %Renamed%
}


*Test it for few files



Regards
SDK.






share|improve this answer























  • Can you give an example of how something like this could be done with AutoHotkey?  Please do not respond in comments; edit your answer to make it clearer and more complete.
    – Scott
    Nov 20 at 4:09















up vote
0
down vote













[Edit] as suggested by Scott



If you can do a little scripting, I recommend autohotkey
You can use a simple regexmatch()
To do your need full



Here is a sample code



Filelist=
Loop, C:Data*.mpg ;Assuming your files in data folder
Filelist = %Filelist%%A_LoopFileFullPath%`n
Loop, parse, filelist, `n
{
Renamed := Regrxreplace(A_Loopfield, "(w.+)s", "_")
Filemove, %A_LoopField%, %Renamed%
}


*Test it for few files



Regards
SDK.






share|improve this answer























  • Can you give an example of how something like this could be done with AutoHotkey?  Please do not respond in comments; edit your answer to make it clearer and more complete.
    – Scott
    Nov 20 at 4:09













up vote
0
down vote










up vote
0
down vote









[Edit] as suggested by Scott



If you can do a little scripting, I recommend autohotkey
You can use a simple regexmatch()
To do your need full



Here is a sample code



Filelist=
Loop, C:Data*.mpg ;Assuming your files in data folder
Filelist = %Filelist%%A_LoopFileFullPath%`n
Loop, parse, filelist, `n
{
Renamed := Regrxreplace(A_Loopfield, "(w.+)s", "_")
Filemove, %A_LoopField%, %Renamed%
}


*Test it for few files



Regards
SDK.






share|improve this answer














[Edit] as suggested by Scott



If you can do a little scripting, I recommend autohotkey
You can use a simple regexmatch()
To do your need full



Here is a sample code



Filelist=
Loop, C:Data*.mpg ;Assuming your files in data folder
Filelist = %Filelist%%A_LoopFileFullPath%`n
Loop, parse, filelist, `n
{
Renamed := Regrxreplace(A_Loopfield, "(w.+)s", "_")
Filemove, %A_LoopField%, %Renamed%
}


*Test it for few files



Regards
SDK.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 10:14

























answered Nov 20 at 3:04









Sudhakar

11




11












  • Can you give an example of how something like this could be done with AutoHotkey?  Please do not respond in comments; edit your answer to make it clearer and more complete.
    – Scott
    Nov 20 at 4:09


















  • Can you give an example of how something like this could be done with AutoHotkey?  Please do not respond in comments; edit your answer to make it clearer and more complete.
    – Scott
    Nov 20 at 4:09
















Can you give an example of how something like this could be done with AutoHotkey?  Please do not respond in comments; edit your answer to make it clearer and more complete.
– Scott
Nov 20 at 4:09




Can you give an example of how something like this could be done with AutoHotkey?  Please do not respond in comments; edit your answer to make it clearer and more complete.
– Scott
Nov 20 at 4:09


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • 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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f416785%2fcut-a-part-from-a-filename-windows-batch%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

What is the Guru Parampara of Kashmiri Shaivism?

Герой Советского Союза

AnyDesk - Fatal Program Failure