Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#1 Post by fhell » 21 Feb 2018 09:17

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#2 Post by aGerman » 21 Feb 2018 15:04

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:

Code: Select all

@echo off &setlocal EnableDelayedExpansion
for /l %%i in () do (
  set /p "scanned="
  echo The data read was "!scanned!"
)
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

fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#3 Post by fhell » 22 Feb 2018 01:59

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#4 Post by aGerman » 22 Feb 2018 03:08

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

fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#5 Post by fhell » 22 Feb 2018 03:33

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#6 Post by aGerman » 22 Feb 2018 05:09

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
Customize variable dst and src. Of course I wasn't able to test it ...

Steffen

fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#7 Post by fhell » 22 Feb 2018 05:30

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!

fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#8 Post by fhell » 22 Feb 2018 05:39

Sorry, they stay active!
I only have the problem with the JPG files

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#9 Post by aGerman » 22 Feb 2018 05:46

Update

Code: Select all

set "file=" &for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "%scanned%.jpg"') do set "file=%%~fi"
to

Code: Select all

set "file=" &for /f "delims=" %%i in ('2^>nul dir /a-d /b /s "??_%scanned%.jpg"') do set "file=%%~fi"
Steffen

fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#10 Post by fhell » 22 Feb 2018 06:00

Great! Its doing exactly what i want now.

Thank you so much!

fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#11 Post by fhell » 22 Feb 2018 07:02

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#12 Post by aGerman » 22 Feb 2018 09:19

Maybe that way

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
Steffen


fhell
Posts: 9
Joined: 21 Feb 2018 08:21

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#14 Post by fhell » 27 Feb 2018 06:21

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

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!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Can anyone write a batch file to do this, please? Symbol LS2208 - Barcode-Scanner

#15 Post by aGerman » 27 Feb 2018 14:09

I'm sure you at least tried to understand the code that I offered. So what did you already try?

Steffen

Post Reply