Script deleting file it should not. RRS feed

  • Question

  • We have a script that runs on one of our servers and it copies files and folders from another server. Once the copy is complete it deletes files off of the server the files and folders are copied from. There is an exclude file setup that contains a list of files and folders the script is supposed to exclude from this process. This has worked for a long time but recently the script has started deleting files that are located in the exclude file. It does not delete any of the excluded folders. 

    Here is the script:


    SET YYYYMMDD=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%
    SET LOGFILE=D:\inetpub\LogFiles\_XCOPY\xc%YYYYMMDD%.log

    echo %date% %time% >> %LOGFILE%
    xcopy \\server.domain.local\dol\* D:\inetpub\_ftproot\dol\ /A /D /EXCLUDE:D:\inetpub\scripts\xcopyExclude.txt /E /V /C /Y /Z >> %LOGFILE%

    del /S /Q /A:A \\server.domain.local\dol\* >> %LOGFILE%
    echo. >> %LOGFILE%

    Here are the contents of the exclude file.


    Any guidance would be appreciated.

    Wednesday, October 3, 2018 7:43 PM


All replies

  • Your question doesn't make much sense, because the del command can't use an exclude file.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, October 3, 2018 9:42 PM
  • That's what I'm thinking but this is how it has been done for some time now, or so I have been told. I just inherited this and I'm thinking we have just been lucky. 
    Wednesday, October 3, 2018 10:22 PM
  • I think I found the culprit. And I found yet another command file that is ran.

    del /S /Q /A:A

    The /A:A switch says to delete files with their file attribute set to A, ready for Archiving. There is yet another command file that is ran on the source server that sets this attribute on all of the files in the directory on the source server using the Attrib +A command. However, the Attrib -A command is used within the same command file to set the file attribute for the files we do not want to delete. All of the command files are ran as scheduled tasks. So now I am wondering if the time between scheduled tasks needs to be adjusted. 

    I have really got to find a better way to do this. 

    Wednesday, October 3, 2018 10:51 PM
  • I would look into robocopy.

    -- Bill Stewart [Bill_Stewart]

    Wednesday, October 3, 2018 11:17 PM