Forum > Windows
Test if I could write to a certain file
dietmar:
Thanks for the tip. I now changed it:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function FileIsWriteable(fn: String) : Boolean;var h: THandle;begin h := FileOpen(fn,fmOpenWrite or fmShareDenyWrite); if (h=-1) then exit(False) else begin FileClose(h); exit(True); end;end;
But the main problem remains. Even for Filenames like "C:\Programs\bla.txt", the function results a file handle... :(
marcio2003:
Hi,
Try it.
http://blog.vitorrubio.com.br/2010/10/obtendo-atributos-de-arquivos-com-o.html
Good job.
lucamar:
--- Quote from: marcio2003 on August 03, 2021, 03:03:34 pm ---Try it.
http://blog.vitorrubio.com.br/2010/10/obtendo-atributos-de-arquivos-com-o.html
--- End quote ---
That's basically what FileIsReadOnly() does, i.e. read the file attributes. Unfortunately that's not enough because the file might not have the read-only attr. set but be nevertheless unwriteable due to file/folder permissions, etc. :(
dietmar:
I tried another solution:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function FileIsWriteable(fn: String) : Boolean;var s: String; h: THandle;begin // try to write random file in same directory repeat s := ExtractFilePath(fn) + MakeRandomString(16) + '.$$$'; until not FileExists(s); h := FileCreate(s,fmShareExclusive); if (h=-1) then exit(False) else begin FileClose(h); exit(True); end;end;
Didn't help either :(
What am I doing wrong? I am very desperate now...
--Dietmar
lucamar:
Have you checked whether the file is indeed created or (for previous attempts) if you can in fact write to that file?
Navigation
[0] Message Index
[#] Next page
[*] Previous page