Programalama > VISUAL BASIC.NET

Etiketler: dosya, kopyalama

Ort. 0
Puan ver:
Üzerine yazmadan:

 DosyaKopyala("D:\Program", "D:\Yedek")

Üzerine yazarak:

 DosyaKopyala("D:\Program", "D:\Yedek", True)

Sub DosyaKopyala(ByVal SourcePath As String, ByVal DestPath As String, _
                    Optional ByVal Overwrite As Boolean = False)
            Try
                Dim SourceDir As DirectoryInfo = New DirectoryInfo(SourcePath)
                Dim DestDir As DirectoryInfo = New DirectoryInfo(DestPath)

                ' the source directory must exist, otherwise throw an exception
                If SourceDir.Exists Then
                    ' if destination SubDir's parent SubDir does not exist throw an exception
                    If Not DestDir.Parent.Exists Then
                        Throw New DirectoryNotFoundException _
                            ("Hedef dizin bulunamadı: " + DestDir.Parent.FullName)
                    End If

                    If Not DestDir.Exists Then
                        DestDir.Create()
                    End If

                    ' copy all the files of the current directory
                    Dim ChildFile As FileInfo
                    For Each ChildFile In SourceDir.GetFiles()
                        If Overwrite Then
                            ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), True)
                        Else
                            ' if Overwrite = false, copy the file only if it does not exist
                            ' this is done to avoid an IOException if a file already exists
                            ' this way the other files can be copied anyway...
                            If Not File.Exists(Path.Combine(DestDir.FullName, ChildFile.Name)) Then
                                ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), _
                                    False)
                            End If
                        End If
                    Next

                    ' copy all the sub-directories by recursively calling this same routine
                    Dim SubDir As DirectoryInfo
                    For Each SubDir In SourceDir.GetDirectories()
                        DosyaKopyala(SubDir.FullName, Path.Combine(DestDir.FullName, _
                             SubDir.Name), Overwrite)
                    Next
                Else
                    Throw New DirectoryNotFoundException("Kaynak dosya bulunamadı: " + _
                        SourceDir.FullName)
                End If
            Catch hata As System.Exception
                MsgBox(hata.Message)
            End Try
        End Sub


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.