Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic - make copy of folder

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Log0ut
454 Views, 2 Replies

iLogic - make copy of folder

Hi

 

I looking way to make copy of folder with all it files and subfolders. For single files we can use System.IO.File.Copy. How about folders?

2 REPLIES 2
Message 2 of 3
Michael.Navara
in reply to: Log0ut
Message 3 of 3
Ralf_Krieg
in reply to: Log0ut

Hello

 

AFAIK no one liner You need to copy recursive step by step.

Imports System.IO
Sub Main
RecursiveFolderCopy("Sourcedirectory", "DestinationDirectory", "TRUE/FALSE")
End Sub

Private Sub RecursiveFolderCopy(ByVal sourceDirectory As String, ByVal destinationDirectory As String, ByVal recursive As Boolean)
    Dim dir As DirectoryInfo = New DirectoryInfo(sourceDirectory)
    Dim dirs() As DirectoryInfo = dir.GetDirectories
    If Not dir.Exists Then
        Throw New DirectoryNotFoundException(String.Format("Source directory {0} does not exist!", sourceDirectory))
    End If
    If Not Directory.Exists(destinationDirectory) Then
        Directory.CreateDirectory(destinationDirectory)
    End If
    Dim files() As FileInfo = dir.GetFiles
    For Each file As FileInfo In files
        Dim temppath As String = System.IO.Path.Combine(destinationDirectory, File.Name)
        File.CopyTo(temppath, False)
    Next
    If Not recursive Then
        Return
    End If
    For Each subdir As DirectoryInfo In dirs
        Dim temppath As String = System.IO.Path.Combine(destinationDirectory, subdir.Name)
        RecursiveFolderCopy(subdir.FullName, temppath, recursive)
    Next
End Sub

R. Krieg
RKW Solutions GmbH
www.rkw-solutions.com

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report