I have managed to find all 'SVN working copies' on Win XP.
I did it using the PowerSell script provided by Alexey Shcherbak.
Here is a summary of the process using the PowerShell method.
Test to see if you have PowerShell already installed.
Windows PowerShell is a command-line shell and scripting environment that brings the power of the .NET Framework to command-line users and script writers.
Test to see if it is already installed by attempting to start it.
To start Windows PowerShell from the Run box, click Start, click Run, and type:
powershell
If that does not work...
Install it
- Download Microsoft Windows PowerShell 1.0 for Windows XP from Cnet.com
- (PowerShell 2 for Windows XP is also available, but I did not use it. (instructions here) )
Once its installed...
Start PowerShell and have a play
Start > All Programs > Windows PowerShell 1.0 > Windows PowerShell
See a brief introduction to PowerShell on YouTube.
Create a PowerShell script
Copy Alexey Shcherbak's PowerSell script (that finds the svn working copies) into a text file and save it as something like C:\PowerShellScripts\FindSvnWorkingDirectories.ps1
.
I modified it slightly to search my C drive and to suppress access denied errors :
$prev = "^$"
Get-ChildItem -ErrorAction SilentlyContinue -Recurse -Force -Include ".svn" -Path "c:\" `
| ?{$_.PSIsContainer -and $_.Fullname.StartsWith($prev)-eq $false}`
| %{ $prev=$_.Fullname.TrimEnd(".svn"); $prev}
To explain what this script does in detail:
$prev = "^$"
initialises $prev
to empty-matching regex; ^$
will never match any meaningful value (except startline-endline). This was needed to pass initial check.
Get-ChildItem -ErrorAction SilentlyContinue -Recurse -Force -Include ".svn" -Path "c:\" `
Gets all objects with name ".svn" (in our case - all files and folders with exact name ".svn"), started from Path, Recursively.
Get-ChildItem
, by default, is an alias of the dir
command.
-ErrorAction SilentlyContinue
- Prevents showing errors such as Access to the path 'C:\System Volume Information' is denied as described here.
-Recurse
means search recusively.
-Force
ensures hidden files are found.
-Include ".svn"
identifies the filename that we are searching for.
-Path "c:\"
idientifies the path to search.
- ` The backtick means continue the statement to the next line.
On the next line:
| ?{$_.PSIsContainer -and $_.Fullname.StartsWith($prev)-eq $false}`
The pipe symbol, |
, pipes the output of Get-ChildItem
into the next cmdlets.
?{...statements... }
is shorthand for the Where-Object
cmdlet.
$_ is
the way to address "each" entry from pipe. It basically says "If entry is a directory" and "fullname does not start with value from $prev", then "Pass entry to next construct".
| %{ $prev=$_.Fullname.TrimEnd(".svn"); $prev}
The entry is then piped to the next statement.
%{}
is shorthand for Foreach-Object
. This construct does 2 things:
- Assign the current folder's fullname to
$prev
(without the ".svn" tail).
- Pass
$prev
to the next pipeline sink.
Allow PowerShell to run the script
By default, for security, PowerShell's ExecutionPolicy
does not let you run PowerShell scripts. So, you need to allow it to do so.
See Running Windows PowerShell Scripts for more info.
I did the following:
Note: The hash symbol (#) is just shotrthand for the command prompt.
Determine the current ExecutionPolicy
:
# Get-ExecutionPolicy
Restricted
If, like mine, its Restricted. Change the policy to allow a script to run:
# Set-ExecutionPolicy RemoteSigned
Run the PowerShell script
Then run the script to find the svn working copies. Note you need to specify the full path to the PowerShell script.
# C:\PowerShellScripts\FindSvnWorkingDirectories.ps1
If there are loads of directories on the PC it may take some time. The results should appear.
Copy and Paste the results to somewhere
I did this by selecting the output text with my mouse. Then, to copy it:
Click the PowerShell icon (in the top-left of the Window) > Edit > Copy
Then I pasted it into a text editor.
Revert the PowerShell Excecution Policy to its original state
Since I rarely use PowerShell and I loosened the Excecution Policy only to run this, one-off, script I am going to revert it back to its orignal state for security.
Determine the current ExecutionPolicy
:
# Get-ExecutionPolicy
RemoteSigned
Change the policy to revert it to its original state:
# Set-ExecutionPolicy Restricted
So that's how I did it.