Perforce Public Knowledge Base - Adding Empty Directories
Downloads Blog Company Integrations Careers Contact Try Free
Menu Search
Reset Search



Adding Empty Directories

« Go Back



How can I add an empty directory to a Perforce depot?


Perforce does not store directories - directories are simply components of the filespec which uniquely identify each file. In order to create an empty directory or structure of empty directories, you need to "anchor" those directories using a place-holder file. The place-holder file is added to Perforce, and then deleted, creating a deleted revision that anchors the directory.

Using this technique creates a directory that appears when selecting "Show Deleted Depot Files" in the P4V filters menu.

Note: Using p4 obliterate to remove the place-holder file removes the directory as well. Use p4 delete instead.

The following examples show how to create a directory named "Empty".

If you would like users to be able to sync the directory structure to their workspace, the "place-holder" file should not be deleted. In this case, you might want to make it a "read-me" file noting the files placeholder status, and skip the step deleting that file.

Using P4V
  1. Select a workspace whose view includes the area of the depot in which you wish to create directories.
  • Create the new directory by right-clicking (in your system's file tree) on the folder where you want to create the directory, and selecting menu item "New Folder...".  When prompted, enter the directory name: Empty.
  • Open a text editor of your choice and create a new file in the Empty directory named ".place-holder". Using a "." in front of the name makes this a hidden file on Linux, Unix, or Mac operating Systems, though it remains visible in Windows workspaces. The file can be empty, it just has to be present.
  • In P4V, right-click on the .place-holder file (if it is not visible, right-click on Empty and select the Refresh Empty menu-item) and select "Mark for Add". Right-click on .place-holder again and select "Submit...".  A submit dialog opens, enter something in the description (such as "Create Empty") and click on "Submit".
  • Now click on the Depot tab. In the depot, you see the Empty directory and the . place-holder file it contains. Right-click on .place-holder, and select "Mark for Delete". Right-click it again and select "Submit...".  A submit dialog opens, enter something in the description and click on "Submit".
  • If you do not see the directory in P4V, confirm that "Show Deleted Files" is selected from the "Filter Depot" menu at the top of the depot tree. 
Using the Command Line

The following commands reproduce the procedure described above. Issue these commands from the directory where you wish to create the new directory.

mkdir Empty
cd Empty
vi .place-holder (on Windows, try "notepad .place-holder")
p4 add .place-holder
p4 submit -d "Create Empty"
p4 delete .place-holder

p4 submit -d "Create Empty"
Related Links
Defining New Local Depots (System Admin Guide)
User's Guide: Adding Files (User's Guide)



Was this article helpful?



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

Characters Remaining: 255