i use perforce for my own source control’d backups. it supports two users for free; perfect for personal use.

it does have two drawbacks – its directory diff tool is *horrible* ( i won’t bore you with the gory details but mercurial piped through beyond compare is beautiful and light years ahead. if i didn’t already have so much in perforce i *might* consider moving over to that instead. )

the point of this post though is that with perforce, in order to add a directory tree’s worth of files, i keep wanting to type:

p4 add …

but if you do you get the (unhelpful) message:

Can’t add filenames with wildcards [@#%*] in them.

perforce rather than adding files recursively thinks you are trying to add a file named “…”.

i don’t know why this particular use case isn’t handled in perforce ( though i can imagine most commands probably operate in the server’s namespace so it would take some tiny bit of extra work. )

i’m used to a microsoft system called source depot in which a similar syntax does work. the command is therefore hard to unlearn. i find myself re-inventing the right command whenever i start a new sub/project.

at any rate: as a public service ;) and for future reference: on windows the equivalent is:

for /R [dir] %i in (*.*) do p4 add %i

where, optionally, “dir” is the base of the files to add.


Comments: Link to heading

Putting the last %i in quotes allows this command … Link to heading

Sam -

Putting the last %i in quotes allows this command to handle paths with spaces in them, otherwise the path files are added to is truncated.

for /R [dir] %i in (*.*) do p4 add “%i”

Thanks for the command though, saved tons of time opening whole trees of files by hand. :)

A faster version of this command: dir /b /s /a-d … Link to heading

Dave Cunningham -

A faster version of this command:

dir /b /s /a-d | p4 -x - add -c [changelist]

I often add a relatively large source base to P4 and found that this command is much faster than the one above - it’ll complete in about 10 seconds while the command above took a minute to add about 10% of the base.

awesome, dave; thanks! Link to heading

ionous -

awesome, dave; thanks!