Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Moderator: DosItHelp
Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Would it be possible for someone to write a batch file for a Bar-code Scanner? (Symbol LS2208 - Bar-code-Scanner )
I need a Folder in a specific location (for exaple C:\Workfolder\2018-02-21) named with the code name that I scan (with a continuous counter) like
Scan: 384121
Folder: 01_384121
and search for a file with the same name in another specific folder (for exaple D:\BackUp) and copy them in this new folder. (if it exist a file with this name)
I'm using Windows 10, if that's important.
Thanks for any answers!
I need a Folder in a specific location (for exaple C:\Workfolder\2018-02-21) named with the code name that I scan (with a continuous counter) like
Scan: 384121
Folder: 01_384121
and search for a file with the same name in another specific folder (for exaple D:\BackUp) and copy them in this new folder. (if it exist a file with this name)
I'm using Windows 10, if that's important.
Thanks for any answers!
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
If ...
1) the scanner is connected via USB and emulates keyboard input
2) the batch window is in the foreground and has the keyboard focus during the scan
3) the scanner automatically sends a line break after the code was scanned
... then it might be possible to read the scanned data using SET /P in a loop.
Those are the preconditions that you can check using this code:
If the data is repeated in the echo line then we can go forward with your tasks to write it to a file etc.
Otherwise you're out of luck.
Steffen
1) the scanner is connected via USB and emulates keyboard input
2) the batch window is in the foreground and has the keyboard focus during the scan
3) the scanner automatically sends a line break after the code was scanned
... then it might be possible to read the scanned data using SET /P in a loop.
Those are the preconditions that you can check using this code:
Code: Select all
@echo off &setlocal EnableDelayedExpansion
for /l %%i in () do (
set /p "scanned="
echo The data read was "!scanned!"
)
Otherwise you're out of luck.
Steffen
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Hi Steffen,
Thanks for the fast answer!
I think the data is repeated, i scan the code BKMRH7NR1GQP9KEG and the echo show this:
BKMRH7NR1GQP9KEG
The data read was "BKMRH7NR1GQP9KEG"
Its that ok?
Thanks!
Thanks for the fast answer!
I think the data is repeated, i scan the code BKMRH7NR1GQP9KEG and the echo show this:
BKMRH7NR1GQP9KEG
The data read was "BKMRH7NR1GQP9KEG"
Its that ok?
Thanks!
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Looks good.
Lets take this example in order to clarify some points. You scanned BKMRH7NR1GQP9KEG ...
1) Do you want to have user interaction at that point? E.g. the user has to confirm that the scanned data shall be processed.
2) The folder where the subfolder shall be created seems to have the current date YYYY-MM-DD. Shall the batch code create it if this folder doesn't exist?
3) I'm not quite certain what to look for in D:\BackUp. Would there be a file with name BKMRH7NR1GQP9KEG that you want to copy? And if so, what's the file extension?
4) What shall happen if no file match in D:\BackUp?
5) As I understood you want to create a subfolder C:\Workfolder\2018-02-22\01_BKMRH7NR1GQP9KEG. The next scan would create a subfolder 02_XXXXXXXXXXXXXX or shall the number be increased only if BKMRH7NR1GQP9KEG was scanned a second time?
Steffen
Lets take this example in order to clarify some points. You scanned BKMRH7NR1GQP9KEG ...
1) Do you want to have user interaction at that point? E.g. the user has to confirm that the scanned data shall be processed.
2) The folder where the subfolder shall be created seems to have the current date YYYY-MM-DD. Shall the batch code create it if this folder doesn't exist?
3) I'm not quite certain what to look for in D:\BackUp. Would there be a file with name BKMRH7NR1GQP9KEG that you want to copy? And if so, what's the file extension?
4) What shall happen if no file match in D:\BackUp?
5) As I understood you want to create a subfolder C:\Workfolder\2018-02-22\01_BKMRH7NR1GQP9KEG. The next scan would create a subfolder 02_XXXXXXXXXXXXXX or shall the number be increased only if BKMRH7NR1GQP9KEG was scanned a second time?
Steffen
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Great,
1) I don't need a user interaction.
2) Yes, the batch code create it if this folder doesn't exist.
3) Would be a file with name BKMRH7NR1GQP9KEG with the extension JPG File (.jpg)
4) If the file dos't exist, the don't copy a file. So nothing happend.
5) The next scan would create a subfolder 02_XXXXXXXXXXXXXX
thank you a lot!
1) I don't need a user interaction.
2) Yes, the batch code create it if this folder doesn't exist.
3) Would be a file with name BKMRH7NR1GQP9KEG with the extension JPG File (.jpg)
4) If the file dos't exist, the don't copy a file. So nothing happend.
5) The next scan would create a subfolder 02_XXXXXXXXXXXXXX
thank you a lot!
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Code: Select all
@echo off &setlocal EnableExtensions DisableDelayedExpansion
set "dst=C:\Workfolder"
set "src=D:\BackUp"
:loop
set "scanned=" &set /p "scanned=Scan the barcode: "
if not defined scanned goto loop
for /f %%i in ('wmic os get LocalDateTime /value') do for /f %%j in ("%%i") do set "%%j"
set "datestamp=%LocalDateTime:~,4%-%LocalDateTime:~4,2%-%LocalDateTime:~6,2%"
if not exist "%dst%\%datestamp%\" md "%dst%\%datestamp%"
pushd "%dst%\%datestamp%"
set "idx=101" &for /f "delims=_" %%i in ('2^>nul dir /ad /b /on "??_*"') do set /a "idx=1%%i + 1"
popd
md "%dst%\%datestamp%\%idx:~-2%_%scanned%"
pushd "%src%"
set "file=" &for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "%scanned%.jpg"') do set "file=%%~fi"
popd
if not defined file (echo JPG file not found.&goto loop)
copy "%file%" "%dst%\%datestamp%\%idx:~-2%_%scanned%\"
goto loop
Steffen
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
That is amazing! Thanks!
Sorry about this but I have a question,
They not find the file in the D:\BackUp folder because the files are always with a counter like 05_BKMRH7NR1GQP9KEG.jpg
It's possible to set that so they can find the file without knowing the first 3 digits?
And it is possible to have this active all the time, so i doesn't need to close and open the script for every new bar-code i scan?
Thank you a lot!
Sorry about this but I have a question,
They not find the file in the D:\BackUp folder because the files are always with a counter like 05_BKMRH7NR1GQP9KEG.jpg
It's possible to set that so they can find the file without knowing the first 3 digits?
And it is possible to have this active all the time, so i doesn't need to close and open the script for every new bar-code i scan?
Thank you a lot!
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Sorry, they stay active!
I only have the problem with the JPG files
I only have the problem with the JPG files
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Updateto
Steffen
Code: Select all
set "file=" &for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "%scanned%.jpg"') do set "file=%%~fi"
Code: Select all
set "file=" &for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "??_%scanned%.jpg"') do set "file=%%~fi"
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Great! Its doing exactly what i want now.
Thank you so much!
Thank you so much!
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Can I ask for a extra thing?
Sometimes y already scan a code days before... it's possible to search the C:\Workfolder destination for jpg files to? and if they already exist, copy them to the new folder?
Thanks!
Sometimes y already scan a code days before... it's possible to search the C:\Workfolder destination for jpg files to? and if they already exist, copy them to the new folder?
Thanks!
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Maybe that way
Steffen
Code: Select all
@echo off &setlocal EnableExtensions DisableDelayedExpansion
set "dst=C:\Workfolder"
set "src=D:\BackUp"
:loop
set "scanned=" &set /p "scanned=Scan the barcode: "
if not defined scanned goto loop
for /f %%i in ('wmic os get LocalDateTime /value') do for /f %%j in ("%%i") do set "%%j"
set "datestamp=%LocalDateTime:~,4%-%LocalDateTime:~4,2%-%LocalDateTime:~6,2%"
if not exist "%dst%\%datestamp%\" md "%dst%\%datestamp%"
pushd "%dst%\%datestamp%"
set "idx=101" &for /f "delims=_" %%i in ('2^>nul dir /ad /b /on "??_*"') do set /a "idx=1%%i + 1"
popd
md "%dst%\%datestamp%\%idx:~-2%_%scanned%"
pushd "%src%"
set "file=" &for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "??_%scanned%.jpg"') do set "file=%%~fi"
popd
if not defined file (
pushd "%dst%"
for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "??_%scanned%.jpg"') do set "file=%%~fi"
popd
)
if not defined file (echo JPG file not found.&goto loop)
copy "%file%" "%dst%\%datestamp%\%idx:~-2%_%scanned%\"
goto loop
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
Hello, sorry for this but i have some problems with this and need some changes (if possible)
I need to search for a Folder named like the barcode (with a counter before, for example 03_987654321 if i scan 987654321) in "dst=C:\Workfolder" and not a specific File. If there exist, copy the files inside to the new Folder.
The problem here is that they are not directly on a sub folder with the actual datestamp. It is perhaps in an other date... Like C:\Workfolder\2018-02-22\03_987654321
The other problem i notice is that they only copy one File from "src=D:\BackUp" and y need to copy all the jpg files they found.
Its that possible?
Thanks!!
I need to search for a Folder named like the barcode (with a counter before, for example 03_987654321 if i scan 987654321) in "dst=C:\Workfolder" and not a specific File. If there exist, copy the files inside to the new Folder.
The problem here is that they are not directly on a sub folder with the actual datestamp. It is perhaps in an other date... Like C:\Workfolder\2018-02-22\03_987654321
The other problem i notice is that they only copy one File from "src=D:\BackUp" and y need to copy all the jpg files they found.
Its that possible?
Thanks!!
Code: Select all
@echo off &setlocal EnableExtensions DisableDelayedExpansion
set "dst=C:\Workfolder"
set "src=D:\BackUp"
:loop
set "scanned=" &set /p "scanned=Scan the barcode: "
if not defined scanned goto loop
for /f %%i in ('wmic os get LocalDateTime /value') do for /f %%j in ("%%i") do set "%%j"
set "datestamp=%LocalDateTime:~,4%-%LocalDateTime:~4,2%-%LocalDateTime:~6,2%"
if not exist "%dst%\%datestamp%\" md "%dst%\%datestamp%"
pushd "%dst%\%datestamp%"
set "idx=101" &for /f "delims=_" %%i in ('2^>nul dir /ad /b /on "??_*"') do set /a "idx=1%%i + 1"
popd
md "%dst%\%datestamp%\%idx:~-2%_%scanned%"
pushd "%src%"
set "file=" &for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "%scanned%.jpg"') do set "file=%%~fi"
popd
if not defined file (echo JPG file not found.&goto loop)
copy "%file%" "%dst%\%datestamp%\%idx:~-2%_%scanned%\"
goto loop
Last edited by Squashman on 27 Feb 2018 09:09, edited 1 time in total.
Reason: MOD EDIT: PLEASE USE CODE TAGS!
Reason: MOD EDIT: PLEASE USE CODE TAGS!
Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner
I'm sure you at least tried to understand the code that I offered. So what did you already try?
Steffen
Steffen