Help with Batch script to move files !!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
simplyeshu
Posts: 5
Joined: 04 Feb 2012 01:23

Help with Batch script to move files !!

#1 Post by simplyeshu » 04 Feb 2012 01:55

Hi Frens...

Any Sample script to move the files from one directory to another directory?
Last edited by simplyeshu on 05 Feb 2012 01:40, edited 1 time in total.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help with Batch script to move files !!

#2 Post by Ed Dyreen » 04 Feb 2012 05:39

'
Hi, I'm not really answering your question, but I introduce some features you may want to play with, or maybe not :)
Move fails if the dir doesn't already exist, beware !

Code: Select all

@echo off &setlocal enableDelayedExpansion

>>"c:\OutputFile.log" (
   ::
   echo.!"!files moving at "!date!-!time!"!"!

   move/y "C:\A\*.*" "C:\Test" &&(
      move/y "C:\B\*.*" "C:\Test" &&(
         echo.!"!files moved at "!date!-!time!"!"!
      )||set/a$err=!errorlevel!
   )||set/a$err=!errorlevel!

   echo.errorlevel=!$err!_
)
type "c:\OutputFile.log"
pause
untested !

simplyeshu
Posts: 5
Joined: 04 Feb 2012 01:23

Re: Help with Batch script to move files !!

#3 Post by simplyeshu » 04 Feb 2012 09:37

Hi Dyreen...


It working perfectly...but after running the batch file i dont want cmd dialog box to stay like that till we press any key it should disappear and also in the output.log file i dont want to see "errorlevel=1_" message. Also i dont want to see the commands running, it should run in the background.

I think we can schedule this batch file to run via task scheduler but i want to know if there is any possibility of running this batch automatically everyday at particular time ?

Can you please suggest ?
Last edited by simplyeshu on 04 Feb 2012 09:47, edited 1 time in total.

simplyeshu
Posts: 5
Joined: 04 Feb 2012 01:23

Re: Help with Batch script to move files !!

#4 Post by simplyeshu » 04 Feb 2012 09:46

I think you have added error levels to distinguish... Wht i can see is it is showing as errorlevel=_ when files are moved if any and showing errorlevel=1_ when there are no files... is it possible to write the script something like if there are no files it should display the message no files to be moved...

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help with Batch script to move files !!

#5 Post by Ed Dyreen » 04 Feb 2012 09:58

'
The code was suggestive, I was hoping you'd play with it, from your 2nd question I assume you are an absolute beginner thus the example is too complex.

Am I arrogant for asking you to study this site ?
It contains 20 lessons that will raise your experience to moderate in only a couple of days :)
http://www.allenware.com/icsw/icswidx.htm

Here is some more suggestive code dealing with your 2nd question

Code: Select all

at /?
schtasks /?
pause

simplyeshu
Posts: 5
Joined: 04 Feb 2012 01:23

Re: Help with Batch script to move files !!

#6 Post by simplyeshu » 04 Feb 2012 10:08

Thank You very much Dyreen.. So kind of you... I will go thru the http://www.allenware.com/icsw/icswidx.htm

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: Help with Batch script to move files !!

#7 Post by Ocalabob » 04 Feb 2012 15:36

Greetings simplyeshu,

Would you consider using a batch file and ROBOCOPY.EXE as a
solution? You will find the resulting log file very detailed and
may decide to remove the 'echo' lines.

For example:

Code: Select all

@echo off
::Limited testing
echo files moving at %date%-%time% >> c:\OutputFile.log
for %%a in (
c:\A
c:\B
) do (
ROBOCOPY %%a C:\TEST /MOV /RH:2200-2300 /LOG+:c:\OutputFile.log
)
echo files moved at %date%-%time% >> c:\OutputFile.log


This could be started from a shortcut and run minimum on the desktop.

Best wishes!

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help with Batch script to move files !!

#8 Post by Squashman » 04 Feb 2012 16:07

If you are running XP you will need to install Robocopy first. It is not native to XP.

simplyeshu
Posts: 5
Joined: 04 Feb 2012 01:23

Re: Help with Batch script to move files !!

#9 Post by simplyeshu » 05 Feb 2012 00:05

Hello Ocalabob,

Thank you very much.

Really the output is looking very nice. Will it work on Windows Server 2008 R2 if i run this as a batch file and schedule it for a particular time ?

I want to insert a new line whenever i run this batch file. I have tried with echo. but its not working.

@echo off
echo.
echo Files moving on %date%-%time% >> c:\OutputFile.log
for %%a in (
c:\A
c:\B
) do (
ROBOCOPY %%a C:\TEST /MOV /LOG+:c:\OutputFile.log
)
echo.
echo Files moved on %date%-%time% >> c:\OutputFile.log

Please advise.

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: Help with Batch script to move files !!

#10 Post by Ocalabob » 05 Feb 2012 09:42

simplyeshu,

I do not have any experience with Windows Server 2008 R2, maybe
someone else can answer that.

To add a blank line to OutputFile.txt redirect your echo command to
the OutputFile.log example:
echo.>>c:\OutputFile.log

or to make it easier to spot in the file try something like:

echo =================>>c:\OutputFile.log

Best wishes.

Post Reply