I Need Help Copying Files
-
I've been assigned the task of creating a batch file to copy a set of files from one directory to another every night. It needs to be over a windows network. My source files are organized like this: \\server\clients\smith\network_diagram\diagram.htm \\server\clients\brown\network_diagram\diagram.htm \\server\clients\johnson\network_diagram\diagram.htm \\server\clients\doe\network_diagram\diagram.htm Destination needs to be like this: \\server\network_diagram\smith\diagram.htm \\server\network_diagram\brown\diagram.htm \\server\network_diagram\johnson\diagram.htm \\server\network_diagram\doe\diagram.htm I need to avoid hard coding each directory in the batch file in case we gain new clients. My problem is creating a loop in a Windows Command Batch file so I'm thinking a small VB app is the way to go. I'm not too experienced in VB at all so I would appreciate help doing a loop like the following:
For all client folders in "\\server\clients\" copy "\\server\clients\_client name_\diagram.htm" to "\\server\network_diagram\_client name_\diagram.htm"
-
I've been assigned the task of creating a batch file to copy a set of files from one directory to another every night. It needs to be over a windows network. My source files are organized like this: \\server\clients\smith\network_diagram\diagram.htm \\server\clients\brown\network_diagram\diagram.htm \\server\clients\johnson\network_diagram\diagram.htm \\server\clients\doe\network_diagram\diagram.htm Destination needs to be like this: \\server\network_diagram\smith\diagram.htm \\server\network_diagram\brown\diagram.htm \\server\network_diagram\johnson\diagram.htm \\server\network_diagram\doe\diagram.htm I need to avoid hard coding each directory in the batch file in case we gain new clients. My problem is creating a loop in a Windows Command Batch file so I'm thinking a small VB app is the way to go. I'm not too experienced in VB at all so I would appreciate help doing a loop like the following:
For all client folders in "\\server\clients\" copy "\\server\clients\_client name_\diagram.htm" to "\\server\network_diagram\_client name_\diagram.htm"
Here is some code that will go through the directory copy you files. Option Explicit Private Const MAX_PATH = 260 Private Const FILE_ATTRIBUTE_DIRECTORY = &H10 Private Const INVALID_HANDLE_VALUE = -1 Private Type FileTime dwLowDateTime As Long dwHighDateTime As Long End Type Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FileTime ftLastAccessTime As FileTime ftLastWriteTime As FileTime nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14 End Type Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long Private Sub Form_Load() On Error Resume Next Dim hSearch&, FileData As WIN32_FIND_DATA, aFolderName$ hSearch& = FindFirstFile("\\server\clients\*.*", FileData) If hSearch& <> INVALID_HANDLE_VALUE Then Do If FileData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then aFolderName$ = Mid$(FileData.cFileName, 1, InStr(1, FileData.cFileName, vbNullChar) - 1) Select Case aFolderName$ Case ".", ".." 'skip Case Else CopyFile "\\server\clients\" & aFolderName$ & "\diagram.htm", "\\server\network_diagram\" & aFolderName$ & "\diagram.htm", True End Select End If FileData.cFileName = "" Loop While FindNextFile(hSearch&, FileData) FindClose (hSearch&) End If End Sub :zzz: iluha
-
Here is some code that will go through the directory copy you files. Option Explicit Private Const MAX_PATH = 260 Private Const FILE_ATTRIBUTE_DIRECTORY = &H10 Private Const INVALID_HANDLE_VALUE = -1 Private Type FileTime dwLowDateTime As Long dwHighDateTime As Long End Type Private Type WIN32_FIND_DATA dwFileAttributes As Long ftCreationTime As FileTime ftLastAccessTime As FileTime ftLastWriteTime As FileTime nFileSizeHigh As Long nFileSizeLow As Long dwReserved0 As Long dwReserved1 As Long cFileName As String * MAX_PATH cAlternate As String * 14 End Type Private Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long Private Sub Form_Load() On Error Resume Next Dim hSearch&, FileData As WIN32_FIND_DATA, aFolderName$ hSearch& = FindFirstFile("\\server\clients\*.*", FileData) If hSearch& <> INVALID_HANDLE_VALUE Then Do If FileData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY Then aFolderName$ = Mid$(FileData.cFileName, 1, InStr(1, FileData.cFileName, vbNullChar) - 1) Select Case aFolderName$ Case ".", ".." 'skip Case Else CopyFile "\\server\clients\" & aFolderName$ & "\diagram.htm", "\\server\network_diagram\" & aFolderName$ & "\diagram.htm", True End Select End If FileData.cFileName = "" Loop While FindNextFile(hSearch&, FileData) FindClose (hSearch&) End If End Sub :zzz: iluha
Thank you. It looks much more than I expected. I need to get VS.NET on here then I can try it out.