Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. I Need Help Copying Files

I Need Help Copying Files

Scheduled Pinned Locked Moved Visual Basic
sysadminhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BrianReeve
    wrote on last edited by
    #1

    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 1 Reply Last reply
    0
    • B BrianReeve

      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 Offline
      I Offline
      iluha
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • I 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

        B Offline
        B Offline
        BrianReeve
        wrote on last edited by
        #3

        Thank you. It looks much more than I expected. I need to get VS.NET on here then I can try it out.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups