Move files from one folder to an active folder BUT move only one file at a time when the active folder is empty

advertisements

Hopefully someone out there can help.

This is what I'm trying to do. I have one folder (Folder A) with .zip's and .z0* (Anything from .z01 to .z09) and I want to move them to a hot folder (Folder B) I've got a .bat file that moves everything the .z0* first that the .zips (See below)

move /-y "c:\Folder A*.z0*" "E:\Folder B\"

move "c:\Folder A*.zip" "E:\Folder B\"

pause

BUT here is the tricky bit (For me anyway)

Folder B is a hot folder that when files go into it a system picks them up and moves to a SFTP site which takes some time because of the size of the files. I have been told I have to move one file at a time when the file before has gone from Folder B and in order .z0* first then the .zip's at the end.

So can I do this in a .bat calling a .vbs or all of it in a .bat or some other way that can be run by task scheduler. Oh forgot to say that I need it to run once a week.

Thanks


@ECHO OFF
SETLOCAL
SET "sourcedir=c:\sourcedir"
SET "destdir=c:\destdir"
FOR %%x IN (
  00 01 02 03 04 05 06 07 08 09 ip
 ) DO IF EXIST "%sourcedir%\*.z%%x" (
 FOR /f "delims=" %%a IN (
   'dir /b /a-d "%sourcedir%\*.z%%x" '
   ) DO (
  SET filename=%%a
  CALL :moveslowly
 )
)
GOTO :EOF

:moveslowly
IF EXIST "%destdir%\*z*" timeout /t 1 >nul&GOTO :moveslowly
MOVE "%sourcedir%\%filename%" "%destdir%\" >nul
GOTO :eof

Only question here is timeout, which may or may not be installed (version-dependent). If it doesn't exist on your machine, then one of the other delay mechanisms could be used like the CHOICE method (also version-dependent) or the PING method.