Jump to content

Checking existance of a file (P4Python API)

Python File Exists p4 fstat

  • Please log in to reply
1 reply to this topic

#1 tollens



  • Members
  • Pip
  • 1 posts

Posted 10 November 2014 - 05:46 AM

I am in the process of writing a trigger using the P4Python API and have encountered a problem; for my script, I need to know if a file specified in a changelist already exists in Perforce. In another thread, the "fstat" command was recommended, but, I can only get this to return "no such file(s)" if I execute the command on the command-line, if I use the P4::run() command with fstat and an invalid file location, my script crashes. Is there a better (any) way to determine if a file exists in Perforce using P4Python?

If relevant, I'm using Perforce version 2013.2/685046 and P4Python version 2014.1/925900 (I believe)

#2 phopkins


    Advanced Member

  • Members
  • PipPipPip
  • 97 posts

Posted 17 November 2014 - 03:36 AM

Good question, I even just tried to do it with Exceptions, and it throws and exception but gives no error, no warning. I'm not sure if you can ask for this to be fixed in here, maybe log it with support or add it to ideax

	def OurException(errorMessage):
		for e in p4.errors:
		p4.run("print", "//playground/main/readme.txt")
	except P4Exception:
			OurException("Failed to get file");

Also tagged with one or more of these keywords: Python, File Exists, p4 fstat

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users