1

I need to check-in the file which is in client workspace. Before check-in i need to verify if the file has been changed. Please tell me how to check this.

Rachan R K
  • 211
  • 2
  • 13
  • If you don't want to check in un-modified files, run `p4 revert -a` before you submit your changes. `p4 revert -a` will revert those files that are not modified. – Bryan Pendleton Dec 26 '18 at 17:03
  • @BryanPendleton I tried this in p4python but failed. What do you mean exactly in p4python? – Payam30 Feb 25 '20 at 13:46

3 Answers3

2

Use the p4 diff -sr command. This will do a diff of opened files and return the names of ones that are unchanged.

Samwise
  • 68,105
  • 3
  • 30
  • 44
1

This is what I came up with in case someone else like me searching for solution

if p4.connected():
            p4.tagged = 0
            # Revert all unchanged files
            result = p4.run("revert","-a","-c"+ "23123")

            # Get the number of files after the unchaged files have been reverted
            numofFiles = p4.run("changes", "-l", "23123")

            # Print the result
            print(result)

            # Print the number of files
            print(len(numofFiles))
Payam30
  • 689
  • 1
  • 5
  • 20
-1

Here is how you can check the creation and modification time of a file

import os.path, time
print("Last modified: %s" % time.ctime(os.path.getmtime("test.txt")))
print("Created: %s" % time.ctime(os.path.getctime("test.txt")))
Hassan ALi
  • 1,313
  • 1
  • 23
  • 51
  • No one is asking for a modification time here. The OP needs to know if the file changed **relative to the Perforce source control repository** – Martijn Pieters Jan 03 '19 at 07:28