batch del files in subfolders only certain file exist


  1. Posts : 3
    Ontario
       #1

    batch del files in subfolders only certain file exist


    Hi all,

    I just want a batch file to delete all files with extension *.P3? in all subfolders on condition only some file exist in these subfolders like *.pkg file

    C:\test\abc\*.P3A, *.pkg
    C:\test\def\*.P3L
    C:\test\ghi\*.P3P, *.pkg

    So the script should only delete *.P3A in abc folder and also *.P3P in ghi folder



    Thanks
      My Computer


  2. Posts : 3,788
    win 8 32 bit
       #2

    Welcome to the forum. if I understand you you want

    Code:
    cd\test
    del *.p3* /s
    Last edited by Brink; 06 Sep 2017 at 12:42. Reason: code box
      My Computer


  3. Posts : 2
    Windows 8 32 bit
       #3

    Batch for Delete all Occurences in SubFolders


    I think you need the following :

    Code:
    ECHO OFF
    CLS
    
    del /s "c:\directory\*.pkg"
    
    @ pause
    Best regards
    Last edited by Brink; 06 Sep 2017 at 12:42. Reason: code box
      My Computer


  4. Posts : 3
    Ontario
    Thread Starter
       #4

    how to delete certain files only some file exist in subfolder in batch


    Thanks to both of your replies.

    What I really want is a batch file to do:

    1) if the *.pkg file exist in subfolder
    2) then delete *.P3? files, it could be *.P3A, *.P3P, or *.P3L

    C:\test\abc\*.P3A, *.pkg
    C:\test\def\*.P3L
    C:\test\ghi\*.P3P, *.pkg

    So the batch script should only delete *.P3A in abc folder and also *.P3P in ghi folder

    Thanks
      My Computer


  5. Posts : 3,788
    win 8 32 bit
       #5

    Post two should do that
      My Computer


  6. Posts : 2
    Windows 8 32 bit
       #6

    Try this


    goodywp said:
    Thanks to both of your replies.

    What I really want is a batch file to do:

    1) if the *.pkg file exist in subfolder
    2) then delete *.P3? files, it could be *.P3A, *.P3P, or *.P3L

    C:\test\abc\*.P3A, *.pkg
    C:\test\def\*.P3L
    C:\test\ghi\*.P3P, *.pkg

    So the batch script should only delete *.P3A in abc folder and also *.P3P in ghi folder

    Thanks
    I'm sorry, I was on the moon

    Ok, you can adapt the following code to what you need, I hope it's what you're looking for.

    Code:
    ECHO OFF
    CLS
    
    if exist c:\directory1\*.pkg goto deleting1
    if exist c:\directory2\*.pkg goto deleting2
    
    :deleting1
    del "c:\directory1\*.pkg"
    
    del "c:\directory1\*.P3A"
    del "c:\directory1\*.P3L"
    del "c:\directory1\*.P3P"
    
    :deleting2
    del "c:\directory2\*.P3A"
    del "c:\directory2\*.P3L"
    del "c:\directory2\*.P3P"
    
    @ pause
    Last edited by Brink; 06 Sep 2017 at 12:42. Reason: code box
      My Computer


  7. Posts : 3
    Ontario
    Thread Starter
       #7

    Hi Samuria,

    there is also the below folder which has *.P3L file and could be deleted as well. The intended is not deleting the file in the folder since it doe not have*.pkg file in this folder

    C:\test\def\*.P3L

    Thanks
      My Computer


  8. Posts : 3,788
    win 8 32 bit
       #8

    It should delete any file that has .P3 and anything else the /s tells it to do the same in sub directory
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 00:04.
Find Us