We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Batch Copy 100 files from folders

jcox3
jcox3 asked
on
Medium Priority
258 Views
Last Modified: 2012-05-06
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

Comment
Watch Question

Top Expert 2009

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

Author

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2009

Commented:
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?

Author

Commented:
yes thats correct just need it to move 100 then stop.
Top Expert 2009
Commented:
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

Author

Commented:
that worked both ways thanks
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.