listperforceworkspace

List workspaces of a user on a specific machine in Perforce


How can I get all Perfoce workspaces of a specific user on a specific machine?

This command let me all workspaces of a specific user on all machines:

P4 clients -u username

Solution

  • Here's a cmd one-liner that does more or less the same thing as pitseeker's:

    for /f "tokens=2" %x in ('p4 clients -u username') do @(echo %x & p4 client -o %x | findstr /r /c:"^Host:")
    

    A somewhat more robust batch file that seems to fit what you're looking for is:

    @echo off
    set USER=%1
    set HOST=%2
    REM Don't forget to double your for-loop percents in batch files,
    REM unlike the one-liner above...
    for /f "tokens=2" %%x in ('p4 clients -u %USER%') do call :CheckClient %%x
    goto :EOF
    
    :CheckClient
    p4 client -o %1 | findstr /r /c:"^Host:" | findstr /i /r /c:"%HOST%$">nul && echo %1
    goto :EOF
    

    Save that and run it with the username as the first parameter and the desired host name as the second. That is, something like showclient elady elady_pc