GazCoder

Afternoon All! (gmt)

I want to make a program to assist in archiving certain files that are used on multiple computers on a small network.. I would make the files exist in the same place on each computer then at a scheduled time say midnight everyday i would move the files from the other PC's to my own so i can back them up onto removable media... e.g.

check files exist...

\\computer1\user\folder
\\computer2\user\folder
\\computer3\user\folder

if files exist move to...

\\mastercomputer\user\folder

then tell output to user x number of files existed and x number of files were successfully moved.

Thats what I want to acheieve but i dont know where to start :( could anyone provide a basic example of working with files on a network moving them to get me started please

Thanks! :)

Gaz


Re: Visual Basic Express Edition Working with files and networks??

Fase

If system.io.file.exists(path) then
filecopy(from, to)
end if




Re: Visual Basic Express Edition Working with files and networks??

GazCoder

Hey Thanks,

here is what I have so far but nothing seems to happen no error and no copying

Public Class Form1
Dim directory As String = "\\computer2\user\folder\"
Dim mypc As String = "c:\archives\auto"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If System.IO.File.Exists(directory) Then
FileCopy(directory, mypc)
End If
Catch ex As Exception
End Try
End Sub
End Class




Re: Visual Basic Express Edition Working with files and networks??

Fase

Those are folders, not files.




Re: Visual Basic Express Edition Working with files and networks??

Fase

Here's some code I wrote to copy folders with the option of subdirectories

Public Class clsFolderCopy

    Public Sub FolderCopy(ByVal strSource As String, ByVal strDestination As String, Optional ByVal bolSubDirectories As Boolean = False)

        'Error Check
        If System.IO.Directory.Exists(strSource) = False Then Exit Sub

        'Directory Info
        Dim SourceDirectoryInfo As New System.IO.DirectoryInfo(strSource)
        Dim DestinationDirectoryInfo As New System.IO.DirectoryInfo(strDestination)
        DestinationDirectoryInfo.Create()
        'Source Data
        Dim Directories As System.IO.DirectoryInfo() = SourceDirectoryInfo.GetDirectories
        Dim Files As System.IO.FileInfo() = SourceDirectoryInfo.GetFiles

        For Each File As System.IO.FileInfo In Files
            FileCopy(File.FullName, strDestination & "\" & File.Name)
        Next

        If bolSubDirectories = True Then
            For Each Directory As System.IO.DirectoryInfo In Directories
                DestinationDirectoryInfo.CreateSubdirectory(Directory.Name)

                Dim NewFolder As New clsFolderCopy
                NewFolder.FolderCopy(strSource & "\" & Directory.Name, strDestination & "\" & Directory.Name, True)
            Next
        End If

    End Sub

End Class





Re: Visual Basic Express Edition Working with files and networks??

GazCoder

Hey fase,

Thanks again! that code looks great but as you probably noticed im pretty new and I am struggeling to see where in the code it is assigning the locations to check if files exists and if they do the location of where they are to be moved

I see SourceDirectoryInfo and DestinationDirectoryInfo but I dont see the bit that says

DestinationDirectoryInfo = "c:\myfolder"

Does that make sense or am I just completly rubbish




Re: Visual Basic Express Edition Working with files and networks??

Fase

Throw the block of code I gave you into a class then do

Public Class Form1
Dim directory As String = "\\computer2\user\folder\"
Dim mypc As String = "c:\archives\auto"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim NewFolder As New clsFolderCopy
NewFolder.FolderCopy(
directory , mypc , TRUE)

End Sub
End Class





Re: Visual Basic Express Edition Working with files and networks??

GazCoder

Thats awesome Fase!

I will try and read through your code working with the MSDN library to learn what's happening.

Many Thanks!