Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help: Need a batch files/VB script to find file extensions with conditions

    I haven't been able to find a program to do this as not quite a "find duplicate file" scenario. Can anyone help?

    Scenario:
    I need to convert drawings from .pdf to .tiff/tif to be able to import into another program.
    However, I often also receive the drawing as a .tiff so don't always have a corresponding .pdf.
    Otherwise it would be a simple solution of deleting all .tiff.

    I have about 3500 project folders, with a squillion subfolders, and backups are getting too large. If I could filter out the duplicate .tiff, that would significantly reduce the total space required.

    Hence, I want to be able to search for and then move all .tiff/tif files to the local recycle bin (ie delete), where there is a matching .pdf in that subfolder location. (reduce size of backups)


    So ideally the location/file path will be part of the file name for finding duplicates, as the file name may not necessarily be unique, and then examine the file extension to find "duplicates".


    Example files:

    1 d:\projects\House1\floorplan.pdf
    2 d:\projects\House1\floorplan.tif
    3 d:\projects\House2\floorplan.pdf
    4 d:\projects\House2\floorplan.tif
    5 d:\projects\House2\revised plan\floorplan.tif
    6 d:\projects\House3\floorplan.pdf
    7 d:\projects\House3\floorplan.tif

    Result:

    I would only want to find (and then delete) files 2,4&7

    I don't want to delete file 5 as there is no matching .pdf in that subfolder...


    No file finder software can do this (as far as I can see)


    A bonus would be to include a variable to search only files older than say 3months....


    Can anyone assist?


    Thanks in advance.

  2. #2
    5 Star Lounger
    Join Date
    Jan 2010
    Location
    Los Angeles, CA
    Posts
    828
    Thanks
    4
    Thanked 38 Times in 34 Posts
    How about PowerShell? Here is a script that should do what you want:

    Code:
    param (
      [string]$dir = ".",
      [switch]$verbose,
      [switch]$whatIf
    )
    
    
    filter CheckDuplicate() {
      $tiff = $_.FullName
      $ext = $_.Extension
      $pdf = $tiff.Substring(0, $tiff.Length - $ext.Length) + ".pdf"
      if (Test-Path $pdf) {
        $_
      }
    }
    
    
    filter DeleteDuplicate() {
      if ($whatIf) {
        Write-Host "Would have deleted $_"
      } else {
        if ($verbose) {
          Write-Host "Deleting $_"
        }
        Remove-Item $_
      }
    }
    
    
    Get-ChildItem $dir -Include *.tiff,*.tif -Recurse | CheckDuplicate | DeleteDuplicate
    To run it, save the above text to a file, say Delete-Dups.ps1, open a PowerShell command window and enter (directory is based on your example):

    .\Delete-Dups.ps1 d:\projects

    Note that this script permanently deletes the files. If you want to see what file the script would delete, add the -whatif switch to the command:

    .\Delete-Dups.ps1 d:\projects -whatif
    Last edited by cafed00d; 2012-02-06 at 23:26. Reason: Handle both .tiff and .tif extensions

  3. #3
    New Lounger
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Many thanks cafed00d

    I am out of the office tomorrow, but will have a play with this later in the week and report back then.


    Again - your assistance is appreciated.


    K

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,170
    Thanks
    47
    Thanked 980 Times in 910 Posts
    I'm sure there are several "duplicate file finder" utilities that will do this.
    The alternative is to set up the backup software to only backup files that are not already backed up.

    cheers, Paul

  5. #5
    New Lounger
    Join Date
    Feb 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for powershell script.

    I endedup with a solution using a script in XYplorer.

    Works a treat.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •