How to use ilogic to move the external file to a new folder ?

How to use ilogic to move the external file to a new folder ?

Anonymous
Not applicable
1,549 Views
9 Replies
Message 1 of 10

How to use ilogic to move the external file to a new folder ?

Anonymous
Not applicable

This is the code what I used but not working


Dim
ss As String="O:\Project\ILOGIC\Stairs" Dim source As String = "O:\Project\ILOGIC\Stairs\Test\28275-STHR-0002.idw" 'change as needed Dim destination As String = "ss" 'change as needed Dim fso = ThisApplication.FileManager.FileSystemObject fso.copyFile(source, destination) 'True to overwrite

 Any thought will help thanks

0 Likes
Accepted solutions (2)
1,550 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Both Strings need to include full file name, not just directory/folder.

Also in your original, you had quotes around ss when setting it as the value.  ss was a variable, so didn't need quotes.

Try this:

Dim source As String = "O:\Project\ILOGIC\Stairs\Test\28275-STHR-0002.idw"
Dim destination As String = "O:\Project\ILOGIC\Stairs\28275-STHR-0002.idw"
System.IO.File.Move(source,destination)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

WCrihfield
Mentor
Mentor

Sorry that was supposed to be a Copy(), not a Move().

Dim source As String = "O:\Project\ILOGIC\Stairs\Test\28275-STHR-0002.idw"
Dim destination As String = "O:\Project\ILOGIC\Stairs\28275-STHR-0002.idw"
System.IO.File.Copy(source,destination)

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Or maybe you were thinking of Inventor's built-in Sub for copying files.  FileManager.CopyFile()

That one has several possible options within its third input variable, which is from the FileManagementEnum.

Dim source As String = "O:\Project\ILOGIC\Stairs\Test\28275-STHR-0002.idw"
Dim destination As String = "O:\Project\ILOGIC\Stairs\28275-STHR-0002.idw"
ThisApplication.FileManager.CopyFile(source, destination, FileManagementEnum.kCopyFileMask)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 10

Anonymous
Not applicable

Than you so much ! If I want to use inputbox to set a new path  how can I make that happen?

0 Likes
Message 6 of 10

Anonymous
Not applicable

I find the way out 


Dim
pp As String = "O:\Project\ILOGIC\Stairs\New folder (2)" Dim source As String = "O:\Project\ILOGIC\Stairs\Test\28275-STHR-0002.idw" Dim destination As String = pp &"\28275-STHR-0002.idw" ThisApplication.FileManager.CopyFile(source, destination, FileManagementEnum.kCopyFileMask)
0 Likes
Message 7 of 10

WCrihfield
Mentor
Mentor
Accepted solution

Also, if you wanted, you could use actual file dialogs to help you choose both the source file, and the destination folder to copy it to.  It requires more code, but may be easier to use if doing this a lot, without having to manually edit the rule each time you want to use it.  Here is just one example of this.

Dim oFileToCopy As String
Dim oDestination As String 'the folder where you want this file copied to

'open file dialog to pick file to copy
Dim oFileDialog As Inventor.FileDialog = Nothing
ThisApplication.CreateFileDialog(oFileDialog)
oFileDialog.Filter = "Autodesk Inventor Files (*.iam;*.dwg;*.idw;*.ipt:*.ipn;*.ide) | *.iam;*.dwg;*.idw;*ipt;*.ipn;*.ide | All files (*.*)|*.*"
oFileDialog.DialogTitle = "SELECT A FILE TO COPY"
oFileDialog.InitialDirectory = ThisDoc.Path
'oFileDialog.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
oFileDialog.CancelError = True
On Error Resume Next
oFileDialog.ShowOpen()
If Err.Number <> 0 Or oFileDialog.FileName = "" Then Exit Sub
oFileToCopy = oFileDialog.FileName
'MsgBox("You selected the following file:" & vbCrLf & oFileToCopy,,"")

'use folder dialog to pick folder to copy it to
Dim oFolderDialog As New System.Windows.Forms.FolderBrowserDialog
oFolderDialog.Description = "SELECT A FOLDER TO COPY THE FILE TO"
oFolderDialog.RootFolder = System.Environment.SpecialFolder.MyComputer
Dim oResult = oFolderDialog.ShowDialog()
If oResult = vbOK Then
	oDestination = oFolderDialog.SelectedPath
End If
'MsgBox("You chose the followig folder: " & vbCrLf & oDestination,,"")

'get just the file name and extension, without the path, from the chosen oFileToCopy
Dim oFName As String = System.IO.Path.GetFileName(oFileToCopy)

'add that to the end of the chosen directory path to form full file name for 'Destination'
oDestination = oDestination & "\" & oFName

'actually copy the file
ThisApplication.FileManager.CopyFile(oFileToCopy, oDestination, FileManagementEnum.kCopyFileMask)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 10

Anonymous
Not applicable

What if to create a new folder ?

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor

I just replied to your other post about creating a new folder, so there are a couple of ideas there.  However, in sticking with this dialog process, if you notice, when the folder dialog is open, after you have selected a folder, the button in the lower left corner of that dialog for creating a new folder becomes available.  You can use that button, then rename the new folder it creates, then just make sure that new folder is selected when you click the OK button.  It will return the path including that new folder, the same way it functioned before.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 10 of 10

Anonymous
Not applicable

I really appreciate that!

0 Likes