Solved

Command Prompt files move from one dir to other . bat

Posted on 2013-01-16
7
741 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 55

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 55

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
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 

Author Comment

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

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 55

Expert Comment

by:Bill Prew
ID: 38785577
Welcome.

~bp
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

695 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