Batch Script for comparing two directories

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Pranil

Thread Starter
Joined
Jan 15, 2013
Messages
5
Hi Guys,
I have to create batch file which will copy the files from one directory to another.
I have done the copy operation using copy command.
After completion of the copying I need to delete all the files from first directory and before deleting I need to check whether all the files are copied or not if any of the file is remaining then I need to skip that file from deleting.
I am stuck on this..........
Please help me !!!!
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
Code:
@echo off
pushd "c:\folder one\"
for %%a in (*.*) do if exist "d:\folder two\%%a" del "%%a"
popd
It doesn't actually check if the file successfully copied, only that a file with the same name exists there.
 

Pranil

Thread Starter
Joined
Jan 15, 2013
Messages
5
Thank you very much for the reply. It is working fine.
1. After Transfer I am deleting the files. I am able to generate the file names. but how to generate the count of deleted files.
2. I am also trying to zip files and I have achieved it using ZIP command given as below.
!DEL %TEMPORARY% /S /Q in temporary we have stored the path of folder and it zip the folder.
I want to generate the name of the files which are zipped in the folder. I don't know how to display the names in the log file.
Code is given as below:
!COPY %TEMPORARY% %TRANSFER%
!DEL %TEMPORARY% /S /Q
!COPY %TRANSFER% %SERVER%
LCD C:\Archive
!ZIP -r "%datetime%".zip %TRANSFER%
!DEL %TRANSFER% /S /Q
 

Pranil

Thread Starter
Joined
Jan 15, 2013
Messages
5
I am running this script for FTP.
1. I need to mentioned the count of deleted files.
2. Count and Name of the files which are zipped in the Zip folder.
3. How to check whether file is successfully copied or not means to perform the delete operation As you said in the above reply.
!COPY C:\Folder1 C:\Folder2
!DEL C:\Folder1 /S /Q
!COPY C:\Folder2 Server_Path
LCD C:\Archive
!ZIP -r xyz.zip C:\Folder2
!DEL C:\Folder2 /S /Q
 

foxidrive

Banned
Joined
Oct 20, 2012
Messages
793
Here's an issue:
You are copying from one folder, and then deleting from the folder *and* the subdirectories.

Also, you can't copy to an FTP server.
 

Pranil

Thread Starter
Joined
Jan 15, 2013
Messages
5
Actually I need to delete all files except which are not copied to another folder but as you have mentioned in the previous reply. I am trying to update it in my code for deleting files but it is generating error for %%a.
what should I do now? :(
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top