Adding a Directory Tree

Info & Tags

Article #:
12
Created:
03/06/07
Modified:
05/16/08
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
  • On other operating systems, if you have Perl you can use the findfiles.perl (Please contact Perforce Technical Support at support@perforce.com for a copy of this script) to generate a file list, then run
    p4 -x filelist add

    where filelist is the name of the file containing the file list. 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 to put them in the depot, you must submit them with

p4 submit
(or the GUI equivalent).

Using P4Win (the Perforce Windows Client):

  • open an Explorer window and locate the folder or files you are adding.
  • drag folders or files from the Explorer to P4Win's Pending Changelist pane.

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.

Using P4V (the Perforce Visual Client)

Files located within the client view that are not currently part of Perforce are viewable from within P4V. By highlighting the file and selecting "File > Mark for Add", a single or multiple files can be added to the default pending change.

Mapping file types

Beginning with the version 2000.1, file types for p4 add can now be selected based on the file's name. The p4 typemap command manages file name-to-type mapping. If a file's name matches an entry in that table, it will be used in preference over the type sensed by the client program. See p4 help filetypes or the p4 Command Reference section on p4 typemap for more details.

Note: The typemap functionality requires a version 2000.1 or greater client and server.