Rename file as per barcode using windows cmd or batch script












2















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.










share|improve this question























  • Use a 2nd stacked for /f to directly parse the output instead of saving it to file

    – LotPings
    Jan 1 at 3:16
















2















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.










share|improve this question























  • Use a 2nd stacked for /f to directly parse the output instead of saving it to file

    – LotPings
    Jan 1 at 3:16














2












2








2








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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 1:58









ANKIT JAINANKIT JAIN

436




436













  • 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

















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












1 Answer
1






active

oldest

votes


















0














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"

)

)





share|improve this answer


























  • 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











  • @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 Called 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 Called 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











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
});


}
});














draft saved

draft discarded


















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









0














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"

)

)





share|improve this answer


























  • 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











  • @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 Called 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 Called 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
















0














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"

)

)





share|improve this answer


























  • 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











  • @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 Called 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 Called 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














0












0








0







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"

)

)





share|improve this answer















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"

)

)






share|improve this answer














share|improve this answer



share|improve this answer








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











  • @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 Called 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 Called 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



















  • 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











  • @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 Called 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 Called 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

















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 Called 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 Called 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 Called 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 Called 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith