Deleting Empty Directories

Info & Tags

Article #:
42
Created:
04/25/07
Modified:
05/16/08

Links

  1. Junction
    Utility to create true symlinks on Windows

TASK

How do I make Perforce delete empty client workspace directories?


SOLUTION

Set the rmdir option in your workspace specification to indicate that client workspace directories should be deleted after you run a command that leaves them empty. The default option normdir will leave empty workspace directories intact.

Perforce removes files from your client workspace directories when you use p4 delete, or when you p4 sync to deleted or nonexistent revisions (including #0 or #none).

Windows Junctions

Warning: The workspace specification option "rmdir" unmaps directory junction maps on Windows!

Some Windows users make use of a type of hidden symlinking called Junctions. In the Windows 2000 Server Resource Kit, for example, there is a utility called linkd.exe, and at the SysInternals Website, at http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx, there is a utility called junction.exe which can create special NTFS symlinks similar to UNIX-style symlinks. These are not just Windows shortcuts; these are actual symlinks.

Unfortunately, attempting to delete a directory which is junction-mapped will unmount or break the junction. Therefore, using the rmdir option in your workspace specification could suddenly make a whole directory seemingly disappear.

Pre-99.2 releases

On Perforce 99.2 or earlier, if you want to remove unneeded, empty workspace directories, you must do so manually.

  • On UNIX, to remove all empty workspace directories (and only the empty directories) you can run the following command from the root of your workspace:
    find . -type d -depth -print | xargs rmdir
  • On Windows, to see if a directory structure is empty, highlight the directory using Explorer and select Files > Properties from the menu. In the MS-DOS shell, you can tell if a directory structure is empty by running:
    dir /s dirname