![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
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 |
![]() |
![]()
|
![]() 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 | |
![]() |
|
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? |
|
![]() |
|
![]() |
|
Here you go.
------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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 |
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.