Rename file as per barcode using windows cmd or batch script
I have some scan images which having barcode i had found cmd barcode scanner tool
bardecode -f C:inputfile1.png -t code128 >> C:outputoutput.txt
this will read the image file and save barcode number in output.txt file.
I want to make a process so this command run on each file in a folder and rename that file with its barcode first 3 or 4 digits.
i try for loop, it runs the command on all png files in folder and print output in file.
for %%i in (C:input*.png) do bardecode -f %%i -t code128 >> C:outputoutput.txt
but i want to use output to rename that file.
batch-file cmd barcode-scanner batch-rename
add a comment |
I have some scan images which having barcode i had found cmd barcode scanner tool
bardecode -f C:inputfile1.png -t code128 >> C:outputoutput.txt
this will read the image file and save barcode number in output.txt file.
I want to make a process so this command run on each file in a folder and rename that file with its barcode first 3 or 4 digits.
i try for loop, it runs the command on all png files in folder and print output in file.
for %%i in (C:input*.png) do bardecode -f %%i -t code128 >> C:outputoutput.txt
but i want to use output to rename that file.
batch-file cmd barcode-scanner batch-rename
Use a 2nd stackedfor /f
to directly parse the output instead of saving it to file
– LotPings
Jan 1 at 3:16
add a comment |
I have some scan images which having barcode i had found cmd barcode scanner tool
bardecode -f C:inputfile1.png -t code128 >> C:outputoutput.txt
this will read the image file and save barcode number in output.txt file.
I want to make a process so this command run on each file in a folder and rename that file with its barcode first 3 or 4 digits.
i try for loop, it runs the command on all png files in folder and print output in file.
for %%i in (C:input*.png) do bardecode -f %%i -t code128 >> C:outputoutput.txt
but i want to use output to rename that file.
batch-file cmd barcode-scanner batch-rename
I have some scan images which having barcode i had found cmd barcode scanner tool
bardecode -f C:inputfile1.png -t code128 >> C:outputoutput.txt
this will read the image file and save barcode number in output.txt file.
I want to make a process so this command run on each file in a folder and rename that file with its barcode first 3 or 4 digits.
i try for loop, it runs the command on all png files in folder and print output in file.
for %%i in (C:input*.png) do bardecode -f %%i -t code128 >> C:outputoutput.txt
but i want to use output to rename that file.
batch-file cmd barcode-scanner batch-rename
batch-file cmd barcode-scanner batch-rename
asked Jan 1 at 1:58
ANKIT JAINANKIT JAIN
436
436
Use a 2nd stackedfor /f
to directly parse the output instead of saving it to file
– LotPings
Jan 1 at 3:16
add a comment |
Use a 2nd stackedfor /f
to directly parse the output instead of saving it to file
– LotPings
Jan 1 at 3:16
Use a 2nd stacked
for /f
to directly parse the output instead of saving it to file– LotPings
Jan 1 at 3:16
Use a 2nd stacked
for /f
to directly parse the output instead of saving it to file– LotPings
Jan 1 at 3:16
add a comment |
1 Answer
1
active
oldest
votes
So, if I understood well, with no layout to test, I image the loop to do this.
If possible, please, provide barcode.exe output layout, without this, there no much references to perform test.
Please note that I need to know the layout of output.txt
to improve my code:
@echo off && cd /d "%~dp0" & setlocal enableextensions enabledelayedexpansion
for /f "tokens=* delims= " %%i in ('dir /b /a-d C:input*.png') do (
for /f "tokens=*" %%I in ('"bardecode.exe" -f "!_name_!" -t code128') do (
set _full_name=%%~fi
set _name_only=%%~ni
set _bar_code_to_rename=%%I
set _bar_code_to_rename=!_bar_code_to_rename:~0,4!-!_name_only!
ren "!_full_name!" "!_bar_code_to_rename!.png"
)
)
Did you consider that as you rename each file in the inner loop, it may be reassessed by the outer loop, and inevitably cycle back to the inner loop again. Also, I would suggest that the renamed file would need to still carry the images extension. As you're using delayed expansion, there should be no need to useCall Set
, justSet
should be sufficient.
– Compo
Jan 1 at 7:49
Please check the last page ofcmd /?
to see all of these special characters.
– double-beep
Jan 1 at 9:39
@Compo, I consider say to you thank you!!
– It was me
Jan 1 at 9:54
@Kaputz, moving from the initial nested loop structure to a single loop andCall
ed label with another loop has actually not improved your code, it has made it worse. Other than now including the original extension, as I previously commented, you have not dealt with the other things I highlighted. When each file is renamed, i.e. when the script returns from theCall
ed label, I would expect that the newly named file will be identified as*.png
, as parsed by the original loop. You also seem to still be usingCall Set
whenSet
is all that's needed.
– Compo
Jan 1 at 10:34
zOk, but no cloud of layout from barcode output! Btw, call set is paranoia!!
– It was me
Jan 1 at 10:51
|
show 1 more 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/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
});
}
});
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%2f53992598%2frename-file-as-per-barcode-using-windows-cmd-or-batch-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So, if I understood well, with no layout to test, I image the loop to do this.
If possible, please, provide barcode.exe output layout, without this, there no much references to perform test.
Please note that I need to know the layout of output.txt
to improve my code:
@echo off && cd /d "%~dp0" & setlocal enableextensions enabledelayedexpansion
for /f "tokens=* delims= " %%i in ('dir /b /a-d C:input*.png') do (
for /f "tokens=*" %%I in ('"bardecode.exe" -f "!_name_!" -t code128') do (
set _full_name=%%~fi
set _name_only=%%~ni
set _bar_code_to_rename=%%I
set _bar_code_to_rename=!_bar_code_to_rename:~0,4!-!_name_only!
ren "!_full_name!" "!_bar_code_to_rename!.png"
)
)
Did you consider that as you rename each file in the inner loop, it may be reassessed by the outer loop, and inevitably cycle back to the inner loop again. Also, I would suggest that the renamed file would need to still carry the images extension. As you're using delayed expansion, there should be no need to useCall Set
, justSet
should be sufficient.
– Compo
Jan 1 at 7:49
Please check the last page ofcmd /?
to see all of these special characters.
– double-beep
Jan 1 at 9:39
@Compo, I consider say to you thank you!!
– It was me
Jan 1 at 9:54
@Kaputz, moving from the initial nested loop structure to a single loop andCall
ed label with another loop has actually not improved your code, it has made it worse. Other than now including the original extension, as I previously commented, you have not dealt with the other things I highlighted. When each file is renamed, i.e. when the script returns from theCall
ed label, I would expect that the newly named file will be identified as*.png
, as parsed by the original loop. You also seem to still be usingCall Set
whenSet
is all that's needed.
– Compo
Jan 1 at 10:34
zOk, but no cloud of layout from barcode output! Btw, call set is paranoia!!
– It was me
Jan 1 at 10:51
|
show 1 more comment
So, if I understood well, with no layout to test, I image the loop to do this.
If possible, please, provide barcode.exe output layout, without this, there no much references to perform test.
Please note that I need to know the layout of output.txt
to improve my code:
@echo off && cd /d "%~dp0" & setlocal enableextensions enabledelayedexpansion
for /f "tokens=* delims= " %%i in ('dir /b /a-d C:input*.png') do (
for /f "tokens=*" %%I in ('"bardecode.exe" -f "!_name_!" -t code128') do (
set _full_name=%%~fi
set _name_only=%%~ni
set _bar_code_to_rename=%%I
set _bar_code_to_rename=!_bar_code_to_rename:~0,4!-!_name_only!
ren "!_full_name!" "!_bar_code_to_rename!.png"
)
)
Did you consider that as you rename each file in the inner loop, it may be reassessed by the outer loop, and inevitably cycle back to the inner loop again. Also, I would suggest that the renamed file would need to still carry the images extension. As you're using delayed expansion, there should be no need to useCall Set
, justSet
should be sufficient.
– Compo
Jan 1 at 7:49
Please check the last page ofcmd /?
to see all of these special characters.
– double-beep
Jan 1 at 9:39
@Compo, I consider say to you thank you!!
– It was me
Jan 1 at 9:54
@Kaputz, moving from the initial nested loop structure to a single loop andCall
ed label with another loop has actually not improved your code, it has made it worse. Other than now including the original extension, as I previously commented, you have not dealt with the other things I highlighted. When each file is renamed, i.e. when the script returns from theCall
ed label, I would expect that the newly named file will be identified as*.png
, as parsed by the original loop. You also seem to still be usingCall Set
whenSet
is all that's needed.
– Compo
Jan 1 at 10:34
zOk, but no cloud of layout from barcode output! Btw, call set is paranoia!!
– It was me
Jan 1 at 10:51
|
show 1 more comment
So, if I understood well, with no layout to test, I image the loop to do this.
If possible, please, provide barcode.exe output layout, without this, there no much references to perform test.
Please note that I need to know the layout of output.txt
to improve my code:
@echo off && cd /d "%~dp0" & setlocal enableextensions enabledelayedexpansion
for /f "tokens=* delims= " %%i in ('dir /b /a-d C:input*.png') do (
for /f "tokens=*" %%I in ('"bardecode.exe" -f "!_name_!" -t code128') do (
set _full_name=%%~fi
set _name_only=%%~ni
set _bar_code_to_rename=%%I
set _bar_code_to_rename=!_bar_code_to_rename:~0,4!-!_name_only!
ren "!_full_name!" "!_bar_code_to_rename!.png"
)
)
So, if I understood well, with no layout to test, I image the loop to do this.
If possible, please, provide barcode.exe output layout, without this, there no much references to perform test.
Please note that I need to know the layout of output.txt
to improve my code:
@echo off && cd /d "%~dp0" & setlocal enableextensions enabledelayedexpansion
for /f "tokens=* delims= " %%i in ('dir /b /a-d C:input*.png') do (
for /f "tokens=*" %%I in ('"bardecode.exe" -f "!_name_!" -t code128') do (
set _full_name=%%~fi
set _name_only=%%~ni
set _bar_code_to_rename=%%I
set _bar_code_to_rename=!_bar_code_to_rename:~0,4!-!_name_only!
ren "!_full_name!" "!_bar_code_to_rename!.png"
)
)
edited Jan 1 at 11:35
answered Jan 1 at 5:16


It was meIt was me
4281418
4281418
Did you consider that as you rename each file in the inner loop, it may be reassessed by the outer loop, and inevitably cycle back to the inner loop again. Also, I would suggest that the renamed file would need to still carry the images extension. As you're using delayed expansion, there should be no need to useCall Set
, justSet
should be sufficient.
– Compo
Jan 1 at 7:49
Please check the last page ofcmd /?
to see all of these special characters.
– double-beep
Jan 1 at 9:39
@Compo, I consider say to you thank you!!
– It was me
Jan 1 at 9:54
@Kaputz, moving from the initial nested loop structure to a single loop andCall
ed label with another loop has actually not improved your code, it has made it worse. Other than now including the original extension, as I previously commented, you have not dealt with the other things I highlighted. When each file is renamed, i.e. when the script returns from theCall
ed label, I would expect that the newly named file will be identified as*.png
, as parsed by the original loop. You also seem to still be usingCall Set
whenSet
is all that's needed.
– Compo
Jan 1 at 10:34
zOk, but no cloud of layout from barcode output! Btw, call set is paranoia!!
– It was me
Jan 1 at 10:51
|
show 1 more comment
Did you consider that as you rename each file in the inner loop, it may be reassessed by the outer loop, and inevitably cycle back to the inner loop again. Also, I would suggest that the renamed file would need to still carry the images extension. As you're using delayed expansion, there should be no need to useCall Set
, justSet
should be sufficient.
– Compo
Jan 1 at 7:49
Please check the last page ofcmd /?
to see all of these special characters.
– double-beep
Jan 1 at 9:39
@Compo, I consider say to you thank you!!
– It was me
Jan 1 at 9:54
@Kaputz, moving from the initial nested loop structure to a single loop andCall
ed label with another loop has actually not improved your code, it has made it worse. Other than now including the original extension, as I previously commented, you have not dealt with the other things I highlighted. When each file is renamed, i.e. when the script returns from theCall
ed label, I would expect that the newly named file will be identified as*.png
, as parsed by the original loop. You also seem to still be usingCall Set
whenSet
is all that's needed.
– Compo
Jan 1 at 10:34
zOk, but no cloud of layout from barcode output! Btw, call set is paranoia!!
– It was me
Jan 1 at 10:51
Did you consider that as you rename each file in the inner loop, it may be reassessed by the outer loop, and inevitably cycle back to the inner loop again. Also, I would suggest that the renamed file would need to still carry the images extension. As you're using delayed expansion, there should be no need to use
Call Set
, just Set
should be sufficient.– Compo
Jan 1 at 7:49
Did you consider that as you rename each file in the inner loop, it may be reassessed by the outer loop, and inevitably cycle back to the inner loop again. Also, I would suggest that the renamed file would need to still carry the images extension. As you're using delayed expansion, there should be no need to use
Call Set
, just Set
should be sufficient.– Compo
Jan 1 at 7:49
Please check the last page of
cmd /?
to see all of these special characters.– double-beep
Jan 1 at 9:39
Please check the last page of
cmd /?
to see all of these special characters.– double-beep
Jan 1 at 9:39
@Compo, I consider say to you thank you!!
– It was me
Jan 1 at 9:54
@Compo, I consider say to you thank you!!
– It was me
Jan 1 at 9:54
@Kaputz, moving from the initial nested loop structure to a single loop and
Call
ed label with another loop has actually not improved your code, it has made it worse. Other than now including the original extension, as I previously commented, you have not dealt with the other things I highlighted. When each file is renamed, i.e. when the script returns from the Call
ed label, I would expect that the newly named file will be identified as *.png
, as parsed by the original loop. You also seem to still be using Call Set
when Set
is all that's needed.– Compo
Jan 1 at 10:34
@Kaputz, moving from the initial nested loop structure to a single loop and
Call
ed label with another loop has actually not improved your code, it has made it worse. Other than now including the original extension, as I previously commented, you have not dealt with the other things I highlighted. When each file is renamed, i.e. when the script returns from the Call
ed label, I would expect that the newly named file will be identified as *.png
, as parsed by the original loop. You also seem to still be using Call Set
when Set
is all that's needed.– Compo
Jan 1 at 10:34
zOk, but no cloud of layout from barcode output! Btw, call set is paranoia!!
– It was me
Jan 1 at 10:51
zOk, but no cloud of layout from barcode output! Btw, call set is paranoia!!
– It was me
Jan 1 at 10:51
|
show 1 more 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%2f53992598%2frename-file-as-per-barcode-using-windows-cmd-or-batch-script%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
Use a 2nd stacked
for /f
to directly parse the output instead of saving it to file– LotPings
Jan 1 at 3:16