views:

2068

answers:

6

Anybody have a script or alias to find untracked (really: unadded) files in a Perforce tree?

EDIT: I updated the accepted answer on this one since it looks like P4V added support for this in the January 2009 release.

+8  A: 

Ahh, one of the Perforce classics :) Yes, it really sucks that there is STILL no easy way for this built into the default commands.

The easiest way is to run a command to find all files under your clients root, and then attempt to add them to the depot. You'll end up with a changelist of all new files and existing files are ignored.

E.g dir /s /b /A-D | p4 -x - add

(use 'find . -type f -print' from a nix command line).

If you want a physical list (in the console or file) then you can pipe on the results of a diff (or add if you also want them in a changelist).

If you're running this within P4Win you can use $r to substitute the client root of the current workspace.

Andrew Grant
+9  A: 

On linux, or if you have gnu-tools installed on windows:

find . -type f -print0 | xargs -0 p4 fstat >/dev/null

This will show an error message for every unaccounted file. If you want to capture that output:

find . -type f -print0 | xargs -0 p4 fstat >/dev/null 2>mylogfile
Mark Harrison
+4  A: 

Alternatively from P4Win, use the ""Local Files not in Depot" option on the left hand view panel.

I don't use P4V much, but I think the equivalent is to select "Hide Local Workspace Files" in the filter dropdown of the Workspace view tab.p4 help fstat

Greg Whitfield
+3  A: 

Under Unix:

find -type f ! -name '*~' -print0| xargs -0 p4 fstat 2>&1|awk '/no such file/{print $1}'

This will print out a list of files that are not added in your client or the Perforce depot. I've used ! -name '*~' to exclude files ending with ~.

ahu
+1  A: 
Ross Patterson
+6  A: 

In the Jan 2009 version of P4V, you can right-click on any folder in your workspace tree and click "reconcile offline work..."

This will do a little processing then bring up a split-tree view of files that are not checked out but have differences from the depot version, or not checked in at all. There may even be a few other categories it brings up.

You can right-click on files in this view and check them out, add them, or even revert them.

It's a very handy tool that's saved my ass a few times.

EDIT: ah the question asked about scripts specifically, but I'll leave this answer here just in case.

tenpn
Awesome. Thanks for the update!
David Joyner
Added a powershell solution in this question: http://stackoverflow.com/questions/3217152/in-perforce-how-can-i-delete-files-from-a-directory-in-my-workspace-where-the-fil/3219246#3219246
tenpn