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.
windows batch-file batch-rename
add a comment |
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.
windows batch-file batch-rename
2
is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nestedFor /Floops, 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
add a comment |
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.
windows batch-file batch-rename
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
windows batch-file batch-rename
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 nestedFor /Floops, 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
add a comment |
2
is PowerShell ok? In PowerShell you can use regular expressions for renaming. It might be possible in pure batch with a few nestedFor /Floops, 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
add a comment |
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%"
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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%"
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
add a comment |
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%"
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
add a comment |
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%"
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%"
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
[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.
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
add a comment |
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
add a comment |
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.
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%2fsuperuser.com%2fquestions%2f416785%2fcut-a-part-from-a-filename-windows-batch%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
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 /Floops, 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