Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Checking file write permissions w/o erasing file
Topic Summary: Checking existence of then appending to a log file
Created On: 24-Apr-2008 18:41
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by jason haury, on Tuesday, April 29, 2008 11:25 PM

Answer:
Thanks! That works just fine!

Here's a link to the other thread you mentioned.

And just in case the other thread gets deleted for being in the wrong forum, i've copied your code here

Jason
 24-Apr-2008 18:41
User is offline View Users Profile Print this message


jason haury

Posts: 39
Joined: 20-Feb-2007

I'm trying to write some code that will first test to see if it can write to a file path before creating a stream (setting a stream using append() will error out if the path is not writable). DOORS has CanOpenFile(string, bool) which will test writablilty if bool is set to True. However, it also erases the file contents! How can I check file permissions for the current user (perhaps using Stats?) without disturbing file contents?

My solution at the moment is to read the file first, and then use CanOpenFile(). If it can open for write, then I'll first restore the file by writing back to the file what was just deleted. This seems to be a poor use of clock cycles though.

Any tips?
Jason

PS. I just accidentally posted this in the General Discussion area. Perhaps a Moderator could delete it from there?
Report this to a Moderator Report this to a Moderator
 25-Apr-2008 13:54
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Here you go.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 25-Apr-2008 17:02
User is offline View Users Profile Print this message


jason haury

Posts: 39
Joined: 20-Feb-2007

Thanks for the code snippet. It didn't quite do what I'd hoped though. I tried it under 4 different conditions (where False is the same as Stat s is null):
1) filename does not exist in a readonly folder - returns False
2) filename does not exist in a writable folder - returns False
3) filename does exist in a readonly folder - returns True
4) filename does exist in a writable folder - returns True

I am looking for a function that will return True for conditions 2 and 4, then False for 1 and 3. In other words, I'd like a function that will tell me whether or not I can write a file in a folder (whether the filename in the path I provide exists or not). If the file can't be created or written to, then I need the function to return false. Lastly, if the file exists and can be written to, I want the file contents to be preserved.

Any thoughts?


Jason
Report this to a Moderator Report this to a Moderator
 25-Apr-2008 17:52
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

See my response in the other forum. It actually appends to an existing file or creates a new one, and gracefully tells you when these operations failed. It doesn't predict whether creating or opening would work. Summmarized:
noError
append
lastError

- Louie
Report this to a Moderator Report this to a Moderator
 25-Apr-2008 18:51
User is offline View Users Profile Print this message


jason haury

Posts: 39
Joined: 20-Feb-2007

Answer Answer
Thanks! That works just fine!

Here's a link to the other thread you mentioned.

And just in case the other thread gets deleted for being in the wrong forum, i've copied your code here

Jason
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.