http://coldfusion.com logo
#cfml-general
Title
# cfml-general
t

Tim

09/22/2022, 2:35 PM
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

rstewart

09/22/2022, 2:40 PM
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

Tim

09/22/2022, 2:43 PM
maybe. I'll try it out. Thanks
m

Michael Schmidt

09/22/2022, 3:11 PM
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

foundeo

09/22/2022, 4:17 PM
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

Tim

09/22/2022, 5:16 PM
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.