Help with Batch script to move files !!
Moderator: DosItHelp
-
- Posts: 5
- Joined: 04 Feb 2012 01:23
Help with Batch script to move files !!
Hi Frens...
Any Sample script to move the files from one directory to another directory?
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.
Re: Help with Batch script to move files !!
'
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 !
untested !
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
-
- Posts: 5
- Joined: 04 Feb 2012 01:23
Re: Help with Batch script to move files !!
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 ?
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.
-
- Posts: 5
- Joined: 04 Feb 2012 01:23
Re: Help with Batch script to move files !!
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...
Re: Help with Batch script to move files !!
'
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
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
-
- Posts: 5
- Joined: 04 Feb 2012 01:23
Re: Help with Batch script to move files !!
Thank You very much Dyreen.. So kind of you... I will go thru the http://www.allenware.com/icsw/icswidx.htm
Re: Help with Batch script to move files !!
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:
This could be started from a shortcut and run minimum on the desktop.
Best wishes!
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!
Re: Help with Batch script to move files !!
If you are running XP you will need to install Robocopy first. It is not native to XP.
-
- Posts: 5
- Joined: 04 Feb 2012 01:23
Re: Help with Batch script to move files !!
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.
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.
Re: Help with Batch script to move files !!
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.
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.