[TIP] Add Directories Recursively To Perforce (P4) Depot

Perforce is an excellent revision control system for the code but the GUIs (P4WIN and P4V) are too slow to be productive. Hence, I like to do most of my work through command lines. Now, the other day I needed to add a directory and all its subdirectories and files to the repository (or perforce depot). This is a trivial task through the GUI. Just drag the top level directory onto the changelist area and the GUI takes care of everything but there is no straightforward way to do this through command line, until, I discovered the “-x” option of P4. So, here it is how to achieve this. Run the following command after cd’ing to the directory you want to add:

For Unix/Linux (or if you have the unix utils installed in windows through GNUWin32, UnixUtils or Cygwin):

find . -type f -print | p4 -x - add</blockquote>

For Windows:

dir /b /s /a-d | p4 -x - add</blockquote>

If you have your own tips and tricks about perforce to carry out tasks easily that do not seem so simple in the first go through command line, please do let me know.

See also