Search code examples
pythonpython-2.7perforcep4python

How to read depot's folders structure by p4python without syncing?


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


Solution

  • 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