3

I'd like to read folders and files structure inside a specified folder path on the P4 depot without syncing it. Is it possible?

smoke_lp
  • 113
  • 1
  • 8
  • 2
    `p4 files ...` will provide required information on CLI. Is it not possible to run this command using `p4.run()`? – gaganso Jun 15 '16 at 15:52
  • 1
    And to determine folder structure, use `p4 dirs` in a similar fashion. – Bryan Pendleton Jun 15 '16 at 23:40
  • @SilentMonk @BryanPendleton thanks guys, `p4.run("dirs", path+'*')` and `p4.run("files", path+'*')` do exactly what i needed – smoke_lp Jun 16 '16 at 09:26
  • 1
    @smoke_lp, you are welcome. I think you should answer your question in the answer section combining both the comments. Other users would find it useful. – gaganso Jun 16 '16 at 09:32

2 Answers2

6

To get subfolders of specified depot path one should use this code

p4.run("dirs", path+'*')

The result will be a list of single-item dictionaries

[{'dir': '//Depot/path/dirname1'}, {'dir': '//Depot/path/dirname2'}]

In order to get all files contained within specified depot path one should use:

p4.run("files", path+'*')

The result will be a list of dictionaries one for each file:

[{'rev': '1', 'time': '1465999632', 'action': 'add', 'type': 'text', 'depotFile': '//Depot/path/dirname1/filename.txt', 'change': '999999'}]

Also please note that specified path must end with a slash /

Thanks to @SilentMonk @BryanPendleton for giving me hints

smoke_lp
  • 113
  • 1
  • 8
0

Note that running using Dirs and Files to recursively iterate through a directory tree is inefficient if you're planning to populate the entire tree.

If you need file info for all files under a directory, including its children, it's orders of magnitudes faster to just issue the "files" command to include the entire tree (i.e. path/... as opposed to path/*).

I suspect this is because the P4 server has no concept of directories, internally. A file's "directory" in P4 is just the last path-separated token in the file's path. So, it has to do extra work to slice its file set into a directory-specific list.

Rich Michaels
  • 1,663
  • 2
  • 12
  • 18