tags:

views:

157

answers:

5

In perforce how can I delete files from a directory in my workspace where the files I want deleted are not part of the workspace?

I have a directory on my file system with files it gets from perforce but after some processes run, it creates some new files in those directories.

Is there a perforce command to remove these generated files that are not part of my workspace?

+1  A: 

You can use p4 nothave to determine the files that are not managed by perforce. Depending on the output of p4 nothave you might be able to do p4 nothave | xargs rm, but be sure to check the result of p4 nothave before running that (so that you don't delete something important by accident).

Michael Aaron Safyan
Weird, my p4 exe does not have a nothave. Is this in linux versions only maybe?
Matt
p4 nothave doesn't exist. You have to fake it with find, "p4 have" and comm(1).
Dominic Mitchell
+1  A: 

You cannot modify/delete files that are not part of your workspace from within perforce. You will have to write external scripts for that.

Rajorshi
A: 

This is a little awkward in powershell, because p4 sends the can't-find-file message to the error stream rather than std out.

ps > $error.clear()
ps > dir | %{p4 fstat -T "haveRev" $_} 2>$null
ps > $error | %{$_.Exception.ToString().Split()[1]} | %{del $_}

The second line should produces errors such as "FILENAME.EXT - no such file(s)." It can be a bit flaky if you have anything other than these exceptions in the error stream, so beware.

tenpn
...still learning powershell, so if there's a quicker way to do this, let me know.
tenpn
+1  A: 

This is my quick implementation of p4 nothave.

#!/bin/bash
#
# List files present, but not in perforce.

tmpd="$(mktemp -d /tmp/nothave.XXXXXXXX)"
trap "rm -rf $tmpd" EXIT HUP INT QUIT TERM

p4 have | awk -F' - ' '{print $2}' | sort >$tmpd/have.txt

root=$(p4 info | awk -F': ' '$1=="Client root"{print $2}')
find $root -type f | sort >$tmpd/find.txt

comm -13 $tmpd/have.txt $tmpd/find.txt

This will produce a list of files, which can then be piped into xargs rm in order to be deleted. Be careful to inspect the list before deleting though. You may well find things you didn't expect in there.

Dominic Mitchell
+1  A: 

If using Linux/Unix, in the Bourne shell family, you can type

p4 files ... 2>&1| grep "no such file" | cut -f1 -d" " | xargs rm

Whether there is an equivalent in Windows I do not know.

Chance