moving folders auotmatically to other folder on server

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
adill441
Posts: 14
Joined: 09 Aug 2012 12:21

moving folders auotmatically to other folder on server

#1 Post by adill441 » 14 Aug 2012 23:20

i want to create a folder so that whenever i move something into it that should be copied to the another folder on server and get deleted from original folder ... is there any command ?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: moving folders auotmatically to other folder on server

#2 Post by foxidrive » 14 Aug 2012 23:31

This should move everything from a folder to a server, and check around once per minute after each run.

Change the coloured bits and test it first.


@echo off
:loop
for /f "delims=" %%a in ('dir "c:\folder\*.*" /b /a-d') do (
move /y "c:\folder\%%a" "\\server\share\"
)
ping -n 60 localhost >nul
goto :loop

adill441
Posts: 14
Joined: 09 Aug 2012 12:21

Re: moving folders auotmatically to other folder on server

#3 Post by adill441 » 15 Aug 2012 00:04

hello Foxi

its not copying the subfolders of that folder which i made... its copying text files and after copying can the move files or folders get deleted automatically

adill441
Posts: 14
Joined: 09 Aug 2012 12:21

Re: moving folders auotmatically to other folder on server

#4 Post by adill441 » 15 Aug 2012 00:11

sorry its deleting the files but solve this its not moving the subfolders

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: moving folders auotmatically to other folder on server

#5 Post by foxidrive » 15 Aug 2012 00:46

This should xcopy the entire folder across into a date and time stamped folder, and then delete the files.

Beware: If any files or folders are dropped into the source folder while it is copying then they may or may not be copied - and will be deleted.
Change the coloured bits and test it before use.

@echo off
:loop
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
echo copy has started
xcopy /s/h/e/k/f/c "c:\folder\*.*" "\\server\share\%dt:~0,8%_%dt:~8,6%\"
rd /s /q "c:\folder\"
md "c:\folder\"
echo copy finished
ping -n 60 localhost >nul
goto :loop

adill441
Posts: 14
Joined: 09 Aug 2012 12:21

Re: moving folders auotmatically to other folder on server

#6 Post by adill441 » 15 Aug 2012 04:34

Hello Foxi

i dont want the date and time stamped folder, because in the server folder we identify the folders by our naming convention , i just want the folder moved to the server folder and get deleted from source folder and one more question if we close the executable file will it stop running every 60 sec and one more question is this possible i have 5 drives in each drive there are many folders in that folders i am going to create a folder named DATA in folders where ever i desired which will be our source folder in which we will moving folders, is it possible that only one executable file for each drive. so that we dont have to go to each folder and run the batch file.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: moving folders auotmatically to other folder on server

#7 Post by foxidrive » 15 Aug 2012 04:48

What will you do about folder name and filename collisions, if they are the same on the 5 drives?

adill441
Posts: 14
Joined: 09 Aug 2012 12:21

Re: moving folders auotmatically to other folder on server

#8 Post by adill441 » 15 Aug 2012 07:05

if it is same also they are not going in same folder in server each folders in each drive will be given a separate server folder path

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: moving folders auotmatically to other folder on server

#9 Post by foxidrive » 15 Aug 2012 17:28

adill441 wrote:Hello Foxi

just remove the time and date stamp folder creation just i need whatever is posted in source folder should be copied in server folder and tell me that if we close the batch will it be still running or we have minimize it and keep it till our work is done...


Removing the time stamp is simple.

You can close the batch file, as long as it is not copying files at the time.

adill441
Posts: 14
Joined: 09 Aug 2012 12:21

Re: moving folders auotmatically to other folder on server

#10 Post by adill441 » 16 Aug 2012 02:12

OkaY Thanks Foxi for your help please remove that date and time stamp and give me the code

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: moving folders auotmatically to other folder on server

#11 Post by foxidrive » 16 Aug 2012 04:04

Try this - I haven't tested it. Increase the 60 to 300 to have it check for new files every 5 minutes.

Code: Select all

@echo off
:loop
echo copy has started
xcopy /s/h/e/k/f/c "c:\folder\*.*" "\\server\share\"
rd /s /q "c:\folder\"
md "c:\folder\"
echo copy has finished
ping -n 60 localhost >nul
goto :loop

adill441
Posts: 14
Joined: 09 Aug 2012 12:21

Re: moving folders auotmatically to other folder on server

#12 Post by adill441 » 16 Aug 2012 04:16

Thank You so much Foxi its working fine

Post Reply