1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Batch Script for comparing two directories

Discussion in 'DOS/Other' started by Pranil, Jan 15, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. Pranil

    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 !!!!
     
  2. foxidrive

    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.
     
  3. Pranil

    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
     
  4. foxidrive

    foxidrive Banned

    Joined:
    Oct 20, 2012
    Messages:
    793
    If you post the actual code then I can see if there are issues.
     
  5. Pranil

    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
     
  6. foxidrive

    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.
     
  7. Pranil

    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? :(
     
  8. Pranil

    Pranil Thread Starter

    Joined:
    Jan 15, 2013
    Messages:
    5
    Please help me out...
     
  9. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1085290

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice