Introduction Here am trying to show common used funtions these are useful in all application .
1 .Coping Files One Directory to Another(dufferent Systems)
Public Sub CopyDirectory(ByVal srcDir As String, ByVal dstDir As String) Dim srcDirectory As IO.DirectoryInfo = New IO.DirectoryInfo(srcDir) Dim fInfo As IO.FileInfo Dim dirInfo As IO.DirectoryInfo For Each fInfo In srcDirectory.GetFiles() If Not IO.Directory.Exists(dstDir) Then IO.Directory.CreateDirectory(dstDir) Try fInfo.CopyTo(IO.Path.Combine(dstDir, fInfo.Name)) Catch ex As Exception MsgBox(ex.message) End Try Application.DoEvents() Next
For Each dirInfo In srcDirectory.GetDirectories() Dim subDirectory As String = IO.Path.Combine(dstDir, dirInfo.Name) Try IO.Directory.CreateDirectory(subDirectory) Catch ex As Exception MsgBox(ex.message) End Try CopyDirectory(dirInfo.FullName, subDirectory) Next
End Sub Ex: strSrc = Replace(Application.StartupPath, "bin", "") + "Upload" strDst = "\\FC1\test" CopyDirectory(strSrc, strDst)
2. Get all System Names from Active Directory
Dim entry As DirectoryEntry = New DirectoryEntry("LDAP://mainserver.com") ‘Active Directory Name Dim mySearcher As DirectorySearcher = New DirectorySearcher(entry) mySearcher.Filter = ("(objectClass=computer)") For Each resEnt As SearchResult In mySearcher.FindAll Dim strName As String Dim position As Integer position = resEnt.GetDirectoryEntry.Name.IndexOf("=") strName = resEnt.GetDirectoryEntry.Name.Substring(position + 1) cmbDstSys.Items.Add(strName) Next entry = Nothing
3. Copying a Selected File to a Specified folder
dlgOpen.ShowDialog() srcPath1 = dlgOpen.FileName Dim finfo As New FileInfo(srcPath1) Dim dirInfo As New DirectoryInfo(Application.StartupPath & "\..\Upload\") If (Not dirInfo.Exists) Then dirInfo.Create() End If Dim fcheck As New FileInfo(Application.StartupPath & "\..\Upload\" & finfo.Name) If (fcheck.Exists) Then If (MsgBox("File already exist. Do u want to overwrite that file...", MsgBoxStyle.Information + MsgBoxStyle.YesNoCancel, "Conformation") = MsgBoxResult.Yes) Then File.Copy(srcPath1, fcheck.FullName, True) Else Exit Sub End If Else File.Copy(srcPath1, fcheck.FullName) End If
|
No responses found. Be the first to respond and make money from revenue sharing program.
|