%FileSet Throws “Directory Does Not Exist” for Network Path — But DirectoryExists() Returns 1
Hi Community,
I’m trying to execute a directory query in InterSystems IRIS using %SQL.Statement, but encountering an unexpected error.
Details:
The following command confirms that the directory exists:
Set dirPath="\\MYNETWORK_DRIVE\DFS-Shared_Product\GXM"
Write ##class(%File).DirectoryExists(dirPath)
It returns 1, meaning the path is valid and accessible.
However, when I try to execute this SQL query:
Set File=##Class(%SQL.Statement).%New()
Set Status=File.%PrepareClassQuery("%File","FileSet")
Set Result=File.%Execute(dirPath)
If Result.%SQLCODE {
Write Result.%Message
}
I get the error:
ERROR #5021: Directory '\\MYNETWORK_DRIVE\DFS-Shared_Product\GXM' does not exist
Interestingly, I can access the same path successfully using the $ZF(-1) command, so it seems to be accessible from the OS level.
Question:
Why does %FileSet report that the directory doesn’t exist, even though it’s accessible both via $ZF(-1) and %File.DirectoryExists()?
Is there any specific configuration or permission requirement for accessing a network path through %FileSet?
Thanks,
Gopal Mani
Comments
The issue you are experiencing with %FileSet reporting that a network directory does not exist, even though %File.DirectoryExists() confirms that the path is valid, can arise due to specific differences in how these methods or queries interact with the operating system and network resources.
Potential Cause:
%FileSetrelies on SQL queries and requires the directory to not only exist but also be accessible in the context of how InterSystems IRIS interacts with the filesystem. Network drives may sometimes have access permissions or visibility issues depending on the user session in which the IRIS service is running. This is consistent with similar issues reported where commands function differently for mapped network drives versus internal directories [1].Mapped Network Drive Access:
For network locations accessed in an IRIS session, ensure:- The IRIS service or process is running with the required permissions and user profile that has access to the network path.
- Sometimes, a script (e.g., using
NET USE) needs to be run during the server startup in%ZSTARTor explicit connection established using$ZF(-1)to map the drives appropriately [1].
Debugging Approach:
- Test the path using
$ZF(-1,...)to verify the visibility of the network drive as seen by the IRIS process. - Consider using the
NormalizeDirectory()method to check that the directory paths are properly normalized and in a valid format [2]. For example:Write ##class(%File).NormalizeDirectory("\\MYNETWORK_DRIVE\DFS-Shared_Product\GXM")
- Test the path using
Error Codes and Messages:
The%FileSeterror stems from lower-level checks that fail to recognize the directory exists on the remote path, despite%File.DirectoryExists()validating its existence directly. This mismatch often points to environmental configuration issues specific to file system paths being interpreted differently under SQL queries versus ObjectScript methods.
Suggestions:
- Verify that the service running InterSystems IRIS has the proper user context and permissions.
- Use the FileSet query under a different test setup using local paths first to isolate the behavior.
- As a workaround, instead of relying solely on
%FileSet, you could build a custom directory listing logic using methods like$ZF(-1)or%File.%Next()related functions for network paths.
Sources:
I just attempted the same sequence using a known valid network path on IRIS 2025.1.1 and it worked as expected. The result set contained the list of folders and files in the specified share.
Are you running both code fragments from the same IRIS Terminal?