How to find untracked files in a Perforce tree? (analogue of svn status)

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.


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

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 ~.


EDIT: Please use p4 status now. There is no need for jumping through hoops anymore. See @ColonelPanic's answer.

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.