Re: When Is A Drive Really Read Only?

new topic     » goto parent     » topic index » view thread      » older message » newer message
ghaberek said...
euphoric said...

Would it be helpful to simply attempt to create a file to the location, then check if it exists? Or maybe the writing of the file itself will produce an error?

From what I'm reading around the internet, yes. Actually testing is the only reliable method.

Here's what I'm doing for now:

public constant 
	LOWERCASE_LETTERS = "abcdefghijklmnopqrstuvwxyz", 
	UPPERCASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 
	LETTERS = LOWERCASE_LETTERS & UPPERCASE_LETTERS, 
	NUMBERS = "0123456789" 
	 
public enum USE_LOWER, USE_UPPER, USE_NUMBERS 
 
public function get_random_string(integer i, sequence options = {USE_LOWER,USE_UPPER,USE_NUMBERS}) 
sequence result, pool = {} 
integer count 
	if length(options) = 0 then 
		pool = LETTERS & NUMBERS 
	else 
		if find(USE_LOWER,options) then 
			pool &= LOWERCASE_LETTERS 
		end if 
		if find(USE_UPPER,options) then 
			pool &= UPPERCASE_LETTERS 
		end if 
		if find(USE_NUMBERS,options) then 
			pool &= NUMBERS 
		end if 
	end if 
	result = "" 
	count = length(pool) 
	for t=1 to i do 
		result &= pool[rand(count)] 
	end for 
	return result 
end function 
 
public function write_to_path(sequence p) 
-- does user have permission to write a file to path 'p' 
integer res 
sequence fname = get_random_string(8) & ".txt" 
	if p[$] != '\\' then 
		p &= '\\' 
	end if 
	fname = p & fname 
	res = create_file(fname) 
	if res then 
		delete_file(fname) 
	end if 
	return res 
end function 
 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu