# Batch Script for comparing two directories



## Pranil (Jan 15, 2013)

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 (Oct 20, 2012)

```
@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 (Jan 15, 2013)

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


----------



## foxidrive (Oct 20, 2012)

If you post the actual code then I can see if there are issues.


----------



## Pranil (Jan 15, 2013)

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 (Oct 20, 2012)

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 (Jan 15, 2013)

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?


----------



## Pranil (Jan 15, 2013)

Please help me out...


----------

