Perforce Public Knowledge Base - Adding a Directory Tree
Reset Search
 

 

Article

Adding a Directory Tree

« Go Back

Information

 
Problem

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

Solution

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

Using 2012.1 or later

The p4 reconcile command allows users to reconcile a client workspace with offline work. With an empty workspace, this command acts like a recursive p4 add command. For example:

p4 reconcile -a

will search an entire workspace for files not under Perforce control, and then add them to a changelist.

Once p4 reconcile is complete, the new files will be added to a changelist -- and the changelist will then need to be submitted to the repository using p4 submit.

Using a release earlier than 2012.1

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 Windows, using PowerShell, run:
     
    Get-ChildItem -r | where {!$_.PSisContainer} | ForEach-Object { p4 add $_.fullname }
  • 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.
Related Links

Feedback

 

Was this article helpful?


   

Feedback

Please tell us how we can make this article more useful.

Characters Remaining: 255