When using a remote Mathematica kernel, how can you test if a file exists on the local front end machine? Of course FileExistsQ cannot be used in this scenario, because it only works on the kernel file system.
There are some undocumented functions in the FrontEnd context, which may do the trick with FrontEndExecute:
Names["FrontEnd`*File*"]
yields
{"FrontEnd`FileBrowse", "FrontEnd`Filename", "FrontEnd`FileName", "FrontEnd`FindFileOnPath", "FrontEnd`ToFileName"}
Answer
I don't have any kernels running on a remote machine so I cannot be sure of how this is handled, but I think it has as good a chance as any of working.
A file that exists:
MathLink`CallFrontEnd[MLFS`FileByteCount["A:\\foo.txt"]]
16
A file that does not exist:
MathLink`CallFrontEnd[MLFS`FileByteCount["A:\\bar.txt"]]
$Failed
Other commands in the same context that may prove useful:
Names["MLFS`*"]
{"MLFS`Close", "MLFS`CopyDirectory", "MLFS`CopyFile", "MLFS`CreateDirectory",
"MLFS`DeleteDirectory", "MLFS`DeleteFile", "MLFS`FileByteCount", "MLFS`FileDate",
"MLFS`FileNames", "MLFS`FileType", "MLFS`Get", "MLFS`OpenAppend", "MLFS`OpenRead",
"MLFS`OpenWrite", "MLFS`Put", "MLFS`PutAppend", "MLFS`Read", "MLFS`RenameDirectory",
"MLFS`RenameFile", "MLFS`SetFileDate", "MLFS`SetStreamPosition", "MLFS`StreamPosition",
"MLFS`WriteString"}
Found via:
Comments
Post a Comment