• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Batch Copy 100 files from folders

i'm working on a data entry/scanning project at work.

we currently have one person scanning paper bubble sheets in to 3 locations depending on what form number its on.

we have 3 forms 20 48 and 100.

i'm looking for an easy way for the data processors to copy 100 files from each of the 3 folders to a drive to be processed and reviwed.

the data structure looks like this

from the scanner
\\server name\scan\form 20
\\server name\scan\form 48
\\server name\scan\form 100

the host machines have an I drive mapped to the \\server name\scan folder

i have found another question on here that wanted to move 100 file then wait 10 sec and start again.

i tested the script and it worked, but i dont need the timer function and cant figure out how to remove it.

 
thanks for your help
:: Move 100 latest files, pause and move again
 
@echo off
set source=I:\scan\form_48
set dest=I:\scan3\form_48
pushd "%source%"
set /a count=0
for /f "delims=" %%a in ('dir /b /a:-d /o:-d 2^>NUL') do call :PROCESS "%%a"
popd
goto :eof
 
:PROCESS
set wait=10
if %count%==100 ping -n %wait% localhost >nul & set count=0
move %1 "%dest%"
set /a count+=1
goto :eof

Open in new window

0
jcox3
Asked:
jcox3
  • 3
  • 3
2 Solutions
 
AmazingTechCommented:
REM'd out. Don't need any of the Count variable now.
:: Move 100 latest files, pause and move again
 
@echo off
set source=I:\scan\form_48
set dest=I:\scan3\form_48
pushd "%source%"
REM set /a count=0
for /f "delims=" %%a in ('dir /b /a:-d /o:-d 2^>NUL') do call :PROCESS "%%a"
popd
goto :eof
 
:PROCESS
REM set wait=10
REM if %count%==100 ping -n %wait% localhost >nul & set count=0
move %1 "%dest%"
REM set /a count+=1
goto :eof

Open in new window

0
 
jcox3Author Commented:
i thought about that before posting, but the little i know about scripting makes me think that wouldn't work cause that is testing if the count = 100.

i just ran it and it moved all 500 of my test files
0
 
Shift-3Commented:
Try this.  It will echo the move commands to be run.  Once you have tested it successfully, remove the ECHO from line 15 to execute them.


@echo off
setlocal enabledelayedexpansion
 
set source=I:\scan
set dest=I:\scan3
set maxfiles=100
 
for %%G in (form_20, form_48, form_100) do call :_process "%source%\%%G" "%dest%\%%G"
pause
goto :eof
 
:_process
set count=0
for /F "tokens=*" %%H in ('dir "%~1" /A:-D /B /O:-D') do (
 ECHO move "%~1\%%H" "%~2"
 set /A count+=1
 if [!count!]==[%maxfiles%] goto :eof
)
goto :eof

Open in new window

0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
AmazingTechCommented:
OK. I took you question as you don't need it to wait 10 secs but wanted it to "start again" continue moving.

So what do you want it to do? Move only 100 and stop then?
0
 
jcox3Author Commented:
yes thats correct just need it to move 100 then stop.
0
 
AmazingTechCommented:
jcox3 looks like Shift-3 has the solution for you.

To modify your existing code we need to move some things around.

You also don't really need the pushd and popd
:: Move 100 latest files and quit
 
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set source=I:\scan\form_48
set dest=I:\scan3\form_48
set count=0
for /f "delims=" %%a in ('dir /b /a:-d /o:-d "%source%" 2^>NUL') do (
if !count!==100 goto EndLoop
move "%%a" "%dest%"
set /a count+=1
)
:EndLoop

Open in new window

0
 
jcox3Author Commented:
that worked both ways thanks
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now