Adding a Directory Tree

Info & Tags

Article #:
12
Created:
03/06/07
Modified:
12/15/09
Tags:
adding files, typemap

TASK

How do I add a whole directory tree of files all at once?


SOLUTION

First, the files you are adding must be in your client workspace. That is, you must have already created them there, or moved them there from another location.

The next steps depend on the platform you are on and the Perforce client program that you are using.

Using P4 (the Perforce command line client program)

Run the following commands from the top of the directory tree from which you want to add files.

  • On UNIX, run:
    find . -type f -print | p4 -x - add
    

    The above find command will find files, but will not find symlinks. Nevertheless, you can add symlinks to Perforce using a similar method. Be aware, however, that symlinks are read-only entites, and that editing a symlink is not the same as editing the file it references.

    To discover the symlinks that exist in your client workspace and assess whether or not you want to version them, run the following command from your client workspace root:

    find . -type l -print
    
    (That's an "el" as in "l" for link)
    

    To add symlinks, run:

    find . -type l -print | p4 -x - add -t symlink
    
  • On Windows, using the MS-DOS command shell, run:
    dir /b /s /a-d | p4 -x - add
    
  • On the Macintosh, using the MPW shell, run:
    files -f -q -r -s | p4 -x - add
    
  • Alternatively, you could try

    p4 add * */* */*/*
    

    and so on, for as many directory levels as exist. When you enter this command, you may get warnings from Perforce about files it cannot add because they already exist, or directories it cannot add because Perforce does not version directories. You may ignore these warnings.

You now have files "opened for add". To put them in the depot, you must submit them with:

p4 submit
(or the GUI equivalent).

Using P4V (the Perforce Visual Client)

Files located within the client view that are not currently part of Perforce are visible within P4V. By selecting the file and executing the command "File > Mark for Add", a single file or multiple files can be added to the default pending changelist. When the pending changelist is submitted, the files are added to Perforce.

Using P4Win (the Perforce Windows Client):

  1. Open an Explorer window and locate the folder or files you are adding.
  2. Drag folders or files from Explorer to P4Win's Pending Changelist pane.
  3. Submit the pending changelist.

Using P4Web (the Perforce Web Client)

Files can also be added to the Perforce depot via P4Web. For details on how to add files to a Perforce depot via P4Web, consult the relevant section of the P4Web manual here.

File types

See Perforce File Type Options for information on how file types are assigned to newly added files.