# PC SDK "GetDirectory" problem

**URL:** <https://tech-community.robotics.abb.com/t/pc-sdk-getdirectory-problem/5822>\
**Category:** Developer Tools\
**Created:** [November 19, 2013, 3:32pm UTC](https://tech-community.robotics.abb.com/t/pc-sdk-getdirectory-problem/5822 "2013-11-19T15:32:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterG](https://avatars.discourse-cdn.com/v4/letter/p/977dab/32.png) [@PeterG](https://tech-community.robotics.abb.com/u/PeterG)\
**Post date:** [November 19, 2013, 3:32pm UTC](https://tech-community.robotics.abb.com/t/pc-sdk-getdirectory-problem/5822/1 "2013-11-19T15:32:44Z")

</div>

Hi All,

Basic concept is to creat a backup on the flexpendent controller and the copy that directory to the local HDD of the PC that is running the SDK but I keep having a problem getting the “CopyDirectory” or “GetDirectory” methods to work!

My Code:  
//string st\_BackUp = this.controller.SystemName;  
string st\_BackUp = this.controller.SystemName + “\_TEST”;  
string st\_RobotDirectoryPathCk = (“”);  
string st\_folderName = “C:\TEMP\_NS”;  
string st\_RobotDirectoryPath = “”;  
string st\_LocalBackupPath = Path.Combine(st\_folderName, st\_BackUp);

//Create string for comparision between path name methods  
st\_RobotDirectoryPathCk = this.controller.FileSystem.RemoteDirectory;

// Create second controller directory path string using different method  
st\_RobotDirectoryPath = controller.GetEnvironmentVariable(“HOME”) + @“/”;

string st\_RobotBackupPath = (st\_RobotDirectoryPath + “/” + st\_BackUp);

// Display path  
MessageBox.Show("current Robot Directory is set to: " + st\_RobotDirectoryPath);

MessageBox.Show("current Robot Directory check is set to: " + st\_RobotDirectoryPathCk);

//Create backup in HOME or BACKUP directory with system name.  
this.controller.Backup(st\_BackUp);  
while (this.controller.BackupInProgress)  
{  
MessageBox.Show(“Backup In progress”);  
}

MessageBox.Show(“Backup complete”);

// Create directory on local system and copy backup to that location.  
Directory.CreateDirectory(st\_LocalBackupPath);  
this.controller.FileSystem.GetDirectory(st\_RobotBackupPath, st\_LocalBackupPath);

I Have tried writing the file paths but stll have the same problem.

error message when running “GetDirectory”: “Operation is not valid due to the current state of the object”

Any help appreciated,

Running RS 5.15.02 VS 2010 express

---

<div class="post-metadata">

**Author:** ![Maukka](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Maukka](https://tech-community.robotics.abb.com/u/Maukka)\
**Post date:** [December 9, 2013, 3:32pm UTC](https://tech-community.robotics.abb.com/t/pc-sdk-getdirectory-problem/5822/2 "2013-12-09T15:32:52Z")

</div>

Hi,

Had the exact problem with the FileSystem. The code below started to work…

‘’’

#  
‘’’ Creates a backup on the robot, copies the backup to PC and removes the backup vrom the robot.  
‘’’   
‘’’ Dir to be created in the /hd0a/BACKUP/ folder at he robot  
‘’’ Directory at local PC to where the backup is being copied  
‘’’ True or false  
‘’’   
Public Function GetBackup(ByVal dirAtRobot As String, ByVal dirAtPC As String) As Boolean  
Try  
’ Login  
\_selController.Logon(UserInfo.DefaultUser)  
’ Create backup  
\_selController.Backup(“(BACKUP)$” & “/” & dirAtRobot)

’ Wait for the backup to finish  
While \_selController.BackupInProgress  
Threading.Thread.Sleep(50)  
Application.DoEvents()  
End While

’ Create dir on local PC, if doesn’t exist  
If Not IO.Directory.Exists(dirAtPC) Then  
IO.Directory.CreateDirectory(dirAtPC)  
End If

’ IMPORTANT! Set the RemoteDirectory!!!  
\_selController.FileSystem.RemoteDirectory = “(BACKUP)$”  
’ Just get the directory from the remote dir  
\_selController.FileSystem.GetDirectory(dirAtRobot, dirAtPC, True)  
’ Remote the directory on the robot  
\_selController.FileSystem.RemoveDirectory(dirAtRobot, True)

Return True  
Catch ex As Exception  
Throw ex  
Finally  
’ Own stuff…  
LogOffController()  
End Try  
End Function

Hope this helps!
