0

The perforce command P4 where (Perforce Command Reference PDF) will give me the branch path, workspace path, and full local path of a specified file.

I would like to know how to access this functionality (specifically the full local path of a file) using the official .net API provided by perforce.

Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98

2 Answers2

1

Assuming you already have a connection object established in the .NET API, try this:

            string[] files = new string[1];
            files[0] = "//depot/Jam/MAIN/src/glob.c";
            P4Command cmd = new P4Command(pRep, "where", true, files);
            Options opts = new Options();

            //run command and get results
            P4CommandResult results = cmd.Run(opts);
            TaggedObjectList list = (results.TaggedOutput);
            foreach (TaggedObject obj in list)
            {
                foreach (String s in obj.Keys)
                {
                    String value = "n/a";
                    obj.TryGetValue(s, out value);
                    Console.Out.WriteLine(s + " = " + value);
                }
            }

That gives you output like this:

depotFile = //depot/Jam/MAIN/src/glob.c
clientFile = //bruno_ws/Jam/MAIN/src/glob.c
path = C:\P4DemoWorkspaces\bruno_ws\Jam\MAIN\src\glob.c
randy-wandisco
  • 3,649
  • 16
  • 11
0

a simpler way is to use the function GetClientFileMappings() from the client object.

API definition here

However I have found the function to be somewhat slow when querying a very large number of files (100k+). Still I highly recommend you batch your query rather than iterate and query. Otherwise works well.

Newtopian
  • 7,543
  • 4
  • 48
  • 71