Updated answer:
This has been somewhat tricky in the past, because there was no built-in way to exclude a directory from a Perforce command. Since 2012 this has changed.
You can have a look at a nice perforce article for this problem.
As of 2012.1, the P4IGNORE
environment variable can be set to designate a file to be used to exclude files from Perforce. Both the Perforce Server (p4d) and client (p4, P4V) need to be 2012.1 or greater. P4IGNORE
's purpose is to ignore files when adding new files to the depot and reconciling workspaces. Like comparable features in other version control systems, P4IGNORE cannot be used to ignore files already under the repository's control.
P4Eclipse manages .p4ignore
files on its own terms.
(see the manual regarding this point here)
Using client views to exclude files and directories:
The traditional method for excluding files and directories in Perforce is to use exclusionary client mappings. See the command reference for Views for full documentation. Example view:
View:
//depot/... //test_ws/depot/...
-//depot/dir/etc/... //test_ws/depot/dir/etc/...
This view will prevent files in dir/etc from being added to the depot. If trying to exclude the directory from read-only queries, use client or relative syntax.
$ p4 files //depot/dir/etc/...
//depot/dir/etc/foo#1 - add change 1186 (text)
//depot/dir/etc/bar#1 - add change 1186 (text)
$ p4 files //test_ws/dir/etc/...
//test_ws/test_ignore/ignoredir/... - file(s) not in client view.
$ cd dir/etc
$ p4 files ...
... - file(s) not in client view.
Alternatively, you can use shell commands to filter your output as desired.
p4 files //depot/dir/... |
awk -F# '{print $1}' |
grep -v "//depot/dir/etc/" |
p4 -x - fstat
which runs p4 fstat on all files under "//depot/dir/
", except for those files under "//depot/dir/etc/
". This directory exclusion is accomplished by listing all of the files, and then using grep to remove those files under the directory to be excluded. The trailing slash in "//depot/dir/etc/
" is necessary to prevent matching directories under "//depot/dir/
" that start with "etc" (for example, "//depot/dir/etc2009
").
Note:
The awk command assumes there are no file names containing the "#" character.
The grep command can also read its patterns from a file, which is useful if you need to exclude multiple directories.
We use the '-x -' flags with the p4 command to use the input as arguments to the corresponding command; see the Perforce Command Line Global Options for more information.