« using switches & .config files to control diagnostic output, app.config | Main | Enabling xml documentation generation and warnings »

recursive source tree checkin script

To recursively check in file in Perforce, wrote the following python script called kzP4Add.py

import os, sys
def visit(arg, dirname, names):
    for n in names:
        r = os.spawnl(os.P_WAIT, r"C:\Program Files\Perforce\p4.exe", r"p4", "add", '"'+os.path.join(dirname, n)+'"')
        print r, dirname, n
def Main():
    if len(sys.argv) != 2:
        print "Usage is kzP4Add "
        for a in sys.argv: print a
        return
    absdir = os.path.abspath(sys.argv[1])
    os.path.walk(absdir, visit, 0)
if __name__ == "__main__":
    Main()

 

Its key that the first argument is the program name, excluding the path info.

Adding the quotes around the filename argument is necessary if the path or name can contain spaces.

The client doesn’t need to be specified.

 

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)