Batch file copy / move from directory to directory

Creating a batch file (DOS / Win cmd)  to move files from one directory to another.   The batch file needs to be able to limit the number of files moved by a count.  For example, when I run the batch file I want only 50 files moved from directory a to directory b.  The nex time I run the batch file it will move another 50 or less depending how many files are left in directory a.
faronAsked:
Who is Participating?
 
ghostdog74Commented:
a vbscript solution

Set objFSO=CreateObject("Scripting.FileSystemObject")
Set wshArgs = WScript.Arguments
i = wshArgs(0)
j=1
strFolder="C:\temp"
Set objFolder = objFSO.GetFolder(strFolder)
iNum = objFolder.Files.Count
For Each strFile In objFolder.Files
          objFSO.MoveFile strFile,"c:\temp1\"&strFile.Name            
          If Int(i) = j Then         
                  Exit For
          End If
          j=j+1
Next
usage: c:\> cscript /nologo myscript.vbs 50
0
 
SteveGTRCommented:
@echo off

setlocal

set srcDir=c:\DirB
set destDir=c:\DirB
set maxFiles=50

pushd "%srcDir%"

set cnt=0

for /f "tokens=*" %%a in ('dir /b /a-d 2^>NUL') do call :MOVEFILE "%%a"

popd

goto :EOF

:MOVEFILE

set /a cnt+=1

if /i %cnt% GEQ goto :EOF

if exist "%destDir%\%~1" del /F "%destDir%\%~1"

move "%~1" "%destDir%"

goto :EOF
0
 
faronAuthor Commented:
When I run this I get an error message "the syntax of  the command is incorrect"  It is refering to the line containing (I suspect).

if /i %cnt% GEQ goto :EOF

If I remove the line all the files get copied from the directory as it does not monitor the count.  I then get an error "the system cannot find the batch label specific -EOFBack"  I get this message once for every file copied.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.