Hi All,
I'm trying to create a batch file to move all the contents of a particular directory to a backup directory
Source directory: F:\Krushant\ABC
Destination backup directory: F:\Krushant\backup
ABC folder contents:
00112CC6
00112E5E
00112EA7
00112CC6.Job
00112E5E.Job
00112EA7.Job
Config.dat
ConSts01.bin
ConSts01.txt
Convert.dbg
FIleCopy.dbg
The one coloured in blue are junk folders
I want to move all the contents of the folder ABC to backup folder, except the 5 files marked in RED
Please suggest a batch file that can acchieve the above task
Its urgent... Please help!!!
Thanks,
Krushant
Batch file to move specific files and folders
Moderator: DosItHelp
Re: Batch file to move specific files and folders
The ROBOCOPY command has many options, including those you need to meet your requirements.
It is standard with Vista and later. If you have an earlier version of Windows it is available in a Microsoft resource kit.
Dave Benham
It is standard with Vista and later. If you have an earlier version of Windows it is available in a Microsoft resource kit.
Dave Benham
Re: Batch file to move specific files and folders
Hi Dave,
This is a client side windows server 2003 environment.
Unfortunately, I won't able to download any resource kit in this server
Please advise if there's any other way we can do this???
Thanks in advance!!!
This is a client side windows server 2003 environment.
Unfortunately, I won't able to download any resource kit in this server
Please advise if there's any other way we can do this???
Thanks in advance!!!
Re: Batch file to move specific files and folders
Hi All,
Just to add:
I have devised a workaround for moving these files and folders.
I'm using the copy/paste->delete->copy back specific files technique
step 1: Copying all the contents of folder ABC to backup
XCOPY "F:\Krushant\ABC" "F:\Krushant\backup" /E /Y
Step 2: Deleting the contents of folder ABC, but not the folder ABC(The below code will take care of that)
cd "F:\Krushant\ABC"
rmdir "F:\Krushant\ABC\" /S /Q
Step 3:
This step will have the code to copy the 5 files above from backup folder back to source ABC folder
This will basically be similar to moving all folder/files
This workaround will definitely work, but I see a potential risk in copying back the 5 files
The 5 files seen above are business critical files.
Is there a risk of these files getting corrupt, while copying back to source folder from backup folder?
Please let me know your thoughts on this!!!
Thanks,
Krushant
Just to add:
I have devised a workaround for moving these files and folders.
I'm using the copy/paste->delete->copy back specific files technique
step 1: Copying all the contents of folder ABC to backup
XCOPY "F:\Krushant\ABC" "F:\Krushant\backup" /E /Y
Step 2: Deleting the contents of folder ABC, but not the folder ABC(The below code will take care of that)
cd "F:\Krushant\ABC"
rmdir "F:\Krushant\ABC\" /S /Q
Step 3:
This step will have the code to copy the 5 files above from backup folder back to source ABC folder
This will basically be similar to moving all folder/files
This workaround will definitely work, but I see a potential risk in copying back the 5 files
The 5 files seen above are business critical files.
Is there a risk of these files getting corrupt, while copying back to source folder from backup folder?
Please let me know your thoughts on this!!!
Thanks,
Krushant
Re: Batch file to move specific files and folders
Do you want to move the directories as well
Or do you want to replicate the directory structure and just move the files
Never mind - your above post answers my questions
Dave Benham
Or do you want to replicate the directory structure and just move the files
Never mind - your above post answers my questions
Dave Benham
Re: Batch file to move specific files and folders
It seems like a slim chance, but I understand your concern. You also have to worry that there is a finite amount of time when the critical files are not where they are supposed to be.krushant wrote:Is there a risk of these files getting corrupt, while copying back to source folder from backup folder?
I like your idea of starting with XCOPY, but why delete the entire source tree and then copy back? Instead you can selectively delete from the source in an efficient manner.
You could base the process on a file containing filenames that should not be moved. You can then easily update the list without having to touch your code.
keep.dat
Code: Select all
Config.dat
ConSts01.bin
ConSts01.txt
Convert.dbg
FIleCopy.dbg
keep.dat
This code is UNTESTED:
Code: Select all
@echo off
XCOPY "F:\Krushant\ABC" "F:\Krushant\backup" /E /Y
F:
cd "F:\Krushant\ABC"
for /f %%d in ('dir /b /ad') do rmdir /s /q %%d
for /f %%f in ('dir /b ^| findstr /vxi /g:keep.dat') do del %%f
::skip the next step if you want to keep the backup of your critical files
for /f %%f in (keep.dat) do del "F:\Krushant\backup\%%f"
My code assumes the KEEP.DAT is in your source tree. It would probably be more secure to put it in some other directory with your batch file and modify the FINDSTR command to reference the absolute path.
Dave Benham
Re: Batch file to move specific files and folders
Thanks Dave... Let me try that... I'll get back to you soon. Thanks for your help !!!