Solved

Command Prompt files move from one dir to other . bat

Posted on 2013-01-16
7
730 Views
Last Modified: 2013-01-16
Hello I hope someone can help me with one sample code in ms-dos command prompt .bat file to move files from one dir to other and repeat automatic again and again endless but this is what I need:

1.-I have 2 dirs first dir called c:\dir1 files will be copied to this directory automatic by users no needed to do nothing there, now I want the .bat file when execute each time the .bat (because remember the .bat must autorun forever and ever), but when execute at first time of each automatic run the .bat must make a pause of 2 minutes then move one file of c:\dir1 (just one file of the dir will be moved the other files not copied must be untouched in c:\dir1) to the other dir called c:\dir2, when runs again the .bat file the .bat will make the pause of 2 minutes then again move only other file from c:\dir1 to c:\dir2 and in that way in an endless loop.
2.-If c:\dir1 is empty then the autorun does nothing just make the pause of 2 minutes.

looking the procedure visually this is what it does:
a.-Initial run check if no files are on c:\dir1 if no files then make a pause of 2 minutes only and re run again the .bat if files found in the dir then:
b.-Make a pause of 2 minutes waiting time (no problem if other 2 minutes of wait time if no files found and after files found by the .bat).
c.-Then move one file of the dir c:\dir1 to c:\dir2 with no particular characteristics or order of the file to be moved just the .bat read the dir and choose the file, only one file of the list of files of that c:\dir1 and move to c:\dir2 like I said.
d.-After move the file the script re run again in othwr words starts again from point "a" from this list I made and on hat way forever and ever the script must run.

If you see the goal is move all files of c:\dir1 to c:\dir2 slowly in other words the c:\dir1 will be enpty after move all files, off course if users copy more files to c:\dir1 the script detect that and continue doing the work like the points above described.

I don't know so much of command prompt but I need that I hope someone can help in sample code to do.
Thank you
0
Comment
Question by:coerrace
  • 4
  • 3
7 Comments
 
LVL 52

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 38785460
I think this does what you described, if I understood it correctly.

@echo off
setlocal

REM Set folder paths to work with
set BaseDir=c:\dir1
set DestDir=c:\dir2

:MainLoop
  REM Delay 2 minutes
  ping 1.1.1.1 -n 1 -w 120000>NUL

  REM If any files in source, copy one, and loop
  for %%F in ("%BaseDir%\*.*") do (
    move "%%~F" "%DestDir%"
    goto :MainLoop
  )

  REM No file found, loop
  goto :MainLoop

Open in new window

~bp
0
 

Author Comment

by:coerrace
ID: 38785510
Works excellent you understand perfect thank you so much just I want to ask if exist any other way to make the pause of 2 minutes because if I'm not connected to Internet the ping command not make the pause of 2 minutes if on other words I need to be connected in Internet to ping works but sometimes the .bat will run in a computer without Internet, then any other way to make the pause?
Thank you
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 38785523
What version of Windows are you running?

Also, would it be acceptable to install a small EXE utility on the machine the script will run on?

~bp
0
Why are Office 365 signatures so complicated?

Trying to setup transport rules for Office 365 email signatures and can’t quite figure it out? Having to test the signature over and over? Make things simple by using Exclaimer Cloud - Signatures for Office 365.

 

Author Comment

by:coerrace
ID: 38785545
The machines can be windows 2008 server.
Thank you
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 38785556
Try this instead:

timeout /T 120

~bp
0
 

Author Comment

by:coerrace
ID: 38785562
works perfect thank you for all!!!!!!!
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 38785577
Welcome.

~bp
0

Featured Post

Why are Office 365 signatures so complicated?

Trying to setup transport rules for Office 365 email signatures and can’t quite figure it out? Having to test the signature over and over? Make things simple by using Exclaimer Cloud - Signatures for Office 365.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now