tags:

views:

851

answers:

8

I have checked out few files on the perforce client. I can get the list of those files by command 'p4 opened' It gives path in the form of //depot/... like I want to know how this can be converted to path on the local path(I mean client path) So that i can create a batch file to backup those just before end of the Day Thanks In advance Uday

+1  A: 

Check your p4 client as there you have defined the mapping for //depot to your filesystem path. Replace //depot with that to get a local path for a file so that you can backup.

I don't know how you can get that programmetically in a batch file.

Bhushan
+2  A: 
p4 where filename

This is the command you're looking for.

It will list the depot path, client path and absolute path of the file on the local file system. Just pipe the output into cut and pick the absolute path and copy them over.

mustpax
The OP mentioned using a batch file which implies Windows. the cut command may not be available.
Jonathon Watney
+5  A: 

You can use p4 where to convert depot filespecs into local filespecs.

To parse the output of p4 where from a Windows batch file, something like the following might help:

for /f "tokens=3" %%i in ('p4 where %my_depot_filespec%') do echo %%i

Note that the body of the for-loop may execute more than once for more complex mappings, such as the ones described in the p4 where documentation. If you need to handle those, you might need to do more complicated parsing.

bk1e
One thing to keep in mind is that p4 where will only report the location of the file. It doesn't check to see if it exists.
Jonathon Watney
@Jonathon: Good point. And even if it exists on the depot, it might not be synced to the client.
bk1e
+3  A: 

You also might want to consider why you feel the need to back up files at the end of each day oustide of using Perforce itself.

You may find that using a development branch and submitting the changes (with the "reopen for edit" flag checked) at the end of each day is actually easier and better. For a start, you are then using Perforce to keep track of your changes, rather than your own manual system.

Using a development branch means that you can do these checkins without risk of messing up your workmates.

Just a suggestion worth considering, that's all.

Greg Whitfield
In my experience maintaining your own inter-submit backups locally outside perforce is quicker and less perilous than trying to maintain branches.
justinhj
This is definitely the correct way to use perforce - unfortunately, in my experience most devs seem too lazy (maybe that is busy) to learn how to do this properly.
cristobalito
+1  A: 

Following BAT script copies the perforce open files from a pending changelist
(%1 command line argument)

p4 opened -c %1 > open-%1.txt
for /F "tokens=1 delims=#" %%i IN (open-%1.txt) do call :add-to-zip %%i

:add-to-zip
for /F "tokens=3" %%j IN ('p4 where %1') do zip [zip-file-name] %%j

A: 

Thanks a ton :-) Was just searching for the command which can give me the client path of the opened files exactly for the same reason of backing up the files. Not just I got the command, but the script too :-)

Akshatha Kamath
hello.. you could have mentioned this in correct answers comment . :)
Uday
+1  A: 

This batch script can zip files into individual change list. for /F "tokens=1,5,6 delims=# " %%a IN ('p4 opened') do for /F "tokens=3" %%j IN ('p4 where %%a') do zip %%b%%c %%j

It will create files like this: change571620.zip change673450.zip change723098.zip defaultchange.zip

+1  A: 

This batch script can zip files into individual change list.

for /F "tokens=1,5,6 delims=# " %%a IN ('p4 opened') do for /F "tokens=3" %%j IN ('p4 where %%a') do zip %%b%%c %%j

It will create files like this:
change571620.zip
change673450.zip
change723098.zip
defaultchange.zip