If( !$file.PSIsContainer -and $file.Extension -like '.xls*' -and $file.Name -match '^.*\-\d+ *. $dt.Columns.Add('DeleteFlag',::MinValue.GetType() ) $dt.Columns.Add('FileTimeStamp',::MinValue.GetType() ) $dt.Columns.Add('CaseNumber',::Empty.GetType() ) $dt.Columns.Add('FileName',::Empty.GetType() ) # create datatable to store file Information in it This should do the trick: $files = Get-ChildItem 'C:\Users\W_Brooker\Documents\Destination\2019\08' -Recurse Compare the files side-by-side to look for duplicates. Navigate to the USB Drive - in this case it's H: Sort the files by Name, Date, or Size. Open File Explorer by pressing Windows+E buttons on your keyboard. $file | Delete-Item - sort -property Datemodified |select -Last 1 Here's how you can do it: Connect your external/USB hard drive to the computer. #If case number is the same keep newest file delete rest $files = Get-ChildItem $dupesource -Filter "08-aaaaaaa" #filter files by case number (7 digit number after date) $dupesource = 'C:\Users\W_Brooker\Documents\Destination\2019\08' I want to compare the case numbers against each other and only keep the newest ones (by date modified) and delete the rest. The anchor point will be the case number just after the date. I've tried different things but now I know the easiest way to filter the files but don't know the syntax. I have a bunch of excel files in different folders which are duplicates but have varying file names due to them being updated.Ġ15 Approved warranty - Turkey - Case-2019 08-1437015 (issue 3),Ġ15 Approved warranty - Turkey - Case-2019 08-1437015 (final issue)Ġ15 Approved warranty - Turkey - Case-2019 08-1437015Ġ15 Approved warranty - Turkey - Case-2019 08-1437015 amended I'm fairly new to PowerShell and I've not been able to find a definitive answer for my problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |