is there a way to check if coldfusion has write ac...
# cfml-general
t
is there a way to check if coldfusion has write access to a directory without actually making a file and checking for an exception?
r
Would
directoryList()
on the parent directory and then evaluation of the attributes for the target directory you’re hoping to write to get you there? Or
directoryList()
on the directory itself and evaluation of the attributes on the “.” entry (if that is part of what comes back)?
t
maybe. I'll try it out. Thanks
m
files = CreateObject("java", "java.nio.file.Files");
paths = CreateObject("java", "java.nio.file.Paths")
path = paths.get("C:\temp\", ["."]);    WriteDump([files.isREadable(path), files.isWritable(path)]);
not a pure coldfusion but it does seem to work
f
try https://cfdocs.org/getfileinfo it returns a struct one of the keys is
canWrite
and it should work on dirs or file paths
example result:
Copy code
{
  "isHidden": false,
  "isSystem": false,
  "isAttributesSupported": false,
  "scheme": "file",
  "path": "/tmp",
  "lastmodified": "September, 22 2022 09:26:27 -0400",
  "isCaseSensitive": false,
  "size": 576,
  "canWrite": true,
  "isModeSupported": false,
  "isArchive": false,
  "name": "tmp",
  "type": "directory",
  "canRead": true,
  "parent": "/"
}
t
Thanks guys. Reporting back, Michael and Pete's options both work. DirectoryList is giving me back empty strings for attribute and mode. But really, getFileInfo is my best option here anyway.