powershell - Is it possible to list only files deleted from TFS using tf dir? - Stack Overflow

admin2025-04-17  2

I have a requirement to list out all of the objects that have been deleted from a folder in VSTS using the TFS version control system (ie: not Git).

I can use PowerShell to run the CLI command

tf dir $/path/to/folder /deleted | Out-File -FilePath /path/to/output.txt

However, this includes undeleted files in addition to deleted files. Is there any way to list only files that were deleted from version control, and not undeleted files currently in version control?

I have a requirement to list out all of the objects that have been deleted from a folder in VSTS using the TFS version control system (ie: not Git).

I can use PowerShell to run the CLI command

tf dir $/path/to/folder /deleted | Out-File -FilePath /path/to/output.txt

However, this includes undeleted files in addition to deleted files. Is there any way to list only files that were deleted from version control, and not undeleted files currently in version control?

Share asked Jan 31 at 2:42 HoppeduppeanutHoppeduppeanut 1,1667 gold badges24 silver badges61 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

With /deleted in the tf command, it will display deleted items and existing items. The deleted items are followed with ;Xn where n is the deletion ID.

We can add a filter to match the ;Xn to get the deleted files. Sample code below:

# Run the tf command to list all items including deleted ones
tf dir $/path/to/folder /deleted | Out-File -FilePath /path/to/output.txt

# Read the output file and filter only the deleted items, then extract the file names
Get-Content /path/to/output.txt | Where-Object { $_ -match ";X\d+$" } | ForEach-Object { $_ -replace ";X\d+$", "" } | Out-File -FilePath /path/to/deleted_files.txt

In this script, ;X\d+$ is a regular expression that matches any line ending with ;X followed by one or more digits. This will ensure that all deleted files, regardless of the number following ;X, are captured. And also remove :Xn for the deleted files in the list with replacement.

转载请注明原文地址:http://anycun.com/QandA/1744882789a88967.html