PCSDK - File handling

Hi all,

I have the following problem, when I try to find out, if a file or directory exists within my C# project (in a virtual and also in a real system):

“ArgumentException: Parameter name: path2”

ControllerFileSystemInfo sInfo = controllerFS.GetFilesAndDirectories(“*”);
Console.WriteLine(sInfo[0].Name); // this is OK (e.g. “Windows” in the virtual system)
Console.WriteLine(sInfo[0].FullName); // this is OK (“ctrl:C:/Windows”)
if (sInfo[0].Exists) Console.WriteLine(“Success”); // ArgumentException

The same happens with DirectoryExists and FileExists with the FullName as path.

What is the best method to find out, if the respective ControllerFileSystemInfo entry relates to a file or directory? The help mentiones a enum FileType, but it seems to be used nowhere?

Thanks very much for your help!
Fabian

Tested with Robotstudio 5.13.03, Win 7 32 and 64bit, VS 2008 and 2010 getting the same error.

Hi

DirectoryExists and FileExists are not working if the complete path is used. You have to use code according to the example below as a workaround.

string homePath = controller.GetEnvironmentVariable(“HOME”) + @“/”;
string temp = “PickMaster”;
controller.FileSystem.RemoteDirectory = homePath;
if (!controller.FileSystem.DirectoryExists(temp))
{
controller.FileSystem.CreateDirectory(temp);
}

The sInfo[0].Exists malfunction is probably a bug that needs to be fixed. We will investigate this.

Hi Lennart,

thanks very much, this helps.
Another "workaround " to see, if a entry is a directory, file or device is

ControllerFileSystemInfo sInfos = controllerFS.GetFilesAndDirectories(“*”);

if (sInfos[0].GetType() == typeof(StorageDeviceInfo)) { // Device }
else if (sInfos[0].GetType() == typeof(ControllerFileInfo)) { // File }
else if (sInfos[0].GetType() == typeof(ControllerDirectoryInfo)) { // Directory }

and then cast it to the respective type.

Best regards

Fabian