Results 1 to 6 of 6

Thread: [RESOLVED] Copy files if destinationation folder is empty, etc

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Resolved [RESOLVED] Copy files if destinationation folder is empty, etc

    Hi,

    I have been able to copy the files form one location to another using this code. However, I noticed that if the files as successfully copied in the text file then someone deletes the files they won't be able to restore the files because of the record in the data file "Secussfully copied". Also I need to add functionality to stop the overwritting of files if some of them are newer than the source. This is what I have tried so far:

    vb Code:
    1. 'copy the files
    2.           If copy = "Copy status:" Or Len(Dir(d, vbDirectory)) = 0 Then VBCopyFiles fullpath & "\*", d

    However, that doesn't work! Although, had that code working at one stage today but I can't remember what I put to make it work. I also tried using the datadiff to determine if the destinination file was older than the source files and if so leave it and contniue through the rest of the files. However it still kept copying all the source folder over to the new destination regardless.

    Hopefully someone understands what I am getting at.


    Nightwalker
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  2. #2

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Copy files if destinationation folder is empty, etc

    Here is the solution I managed to came up with.

    vb Code:
    1. Const VS_FFI_SIGNATURE = &HFEEF04BD
    2.     Const VS_FFI_STRUCVERSION = &H10000
    3.     Const VS_FFI_FILEFLAGSMASK = &H3F&
    4.     Const VS_FF_DEBUG = &H1
    5.     Const VS_FF_PRERELEASE = &H2
    6.     Const VS_FF_PATCHED = &H4
    7.     Const VS_FF_PRIVATEBUILD = &H8
    8.     Const VS_FF_INFOINFERRED = &H10
    9.     Const VS_FF_SPECIALBUILD = &H20
    10.     Const VOS_UNKNOWN = &H0
    11.     Const VOS_DOS = &H10000
    12.     Const VOS_OS216 = &H20000
    13.     Const VOS_OS232 = &H30000
    14.     Const VOS_NT = &H40000
    15.     Const VOS__BASE = &H0
    16.     Const VOS__WINDOWS16 = &H1
    17.     Const VOS__PM16 = &H2
    18.     Const VOS__PM32 = &H3
    19.     Const VOS__WINDOWS32 = &H4
    20.     Const VOS_DOS_WINDOWS16 = &H10001
    21.     Const VOS_DOS_WINDOWS32 = &H10004
    22.     Const VOS_OS216_PM16 = &H20002
    23.     Const VOS_OS232_PM32 = &H30003
    24.     Const VOS_NT_WINDOWS32 = &H40004
    25.     Const VFT_UNKNOWN = &H0
    26.     Const VFT_APP = &H1
    27.     Const VFT_DLL = &H2
    28.     Const VFT_DRV = &H3
    29.     Const VFT_FONT = &H4
    30.     Const VFT_VXD = &H5
    31.     Const VFT_STATIC_LIB = &H7
    32.     Const VFT2_UNKNOWN = &H0
    33.     Const VFT2_DRV_PRINTER = &H1
    34.     Const VFT2_DRV_KEYBOARD = &H2
    35.     Const VFT2_DRV_LANGUAGE = &H3
    36.     Const VFT2_DRV_DISPLAY = &H4
    37.     Const VFT2_DRV_MOUSE = &H5
    38.     Const VFT2_DRV_NETWORK = &H6
    39.     Const VFT2_DRV_SYSTEM = &H7
    40.     Const VFT2_DRV_INSTALLABLE = &H8
    41.     Const VFT2_DRV_SOUND = &H9
    42.     Const VFT2_DRV_COMM = &HA
    43.     Private Type VS_FIXEDFILEINFO
    44.        dwSignature As Long
    45.        dwStrucVersionl As Integer     '  e.g. = &h0000 = 0
    46.        dwStrucVersionh As Integer     '  e.g. = &h0042 = .42
    47.        dwFileVersionMSl As Integer    '  e.g. = &h0003 = 3
    48.        dwFileVersionMSh As Integer    '  e.g. = &h0075 = .75
    49.        dwFileVersionLSl As Integer    '  e.g. = &h0000 = 0
    50.        dwFileVersionLSh As Integer    '  e.g. = &h0031 = .31
    51.        dwProductVersionMSl As Integer '  e.g. = &h0003 = 3
    52.        dwProductVersionMSh As Integer '  e.g. = &h0010 = .1
    53.        dwProductVersionLSl As Integer '  e.g. = &h0000 = 0
    54.        dwProductVersionLSh As Integer '  e.g. = &h0031 = .31
    55.        dwFileFlagsMask As Long        '  = &h3F for version "0.42"
    56.        dwFileFlags As Long            '  e.g. VFF_DEBUG Or VFF_PRERELEASE
    57.        dwFileOS As Long               '  e.g. VOS_DOS_WINDOWS16
    58.        dwFileType As Long             '  e.g. VFT_DRIVER
    59.        dwFileSubtype As Long          '  e.g. VFT2_DRV_KEYBOARD
    60.        dwFileDateMS As Long           '  e.g. 0
    61.        dwFileDateLS As Long           '  e.g. 0
    62.     End Type
    63.                          Private Type SHFILEOPSTRUCT
    64.     hWnd As Long
    65.     wFunc As Long
    66.     pFrom As String
    67.     pTo As String
    68.     fFlags As Integer
    69.     fAnyOperationsAborted As Long
    70.     hNameMappings As Long
    71.     lpszProgressTitle As Long ' only used if FOF_SIMPLEPROGRESS, sets dialog title
    72. End Type
    73.     Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
    74. ' Available Operations
    75. Private Const FO_COPY = &H2 ' Copy File/Folder
    76. Private Const FO_DELETE = &H3  ' Delete File/Folder
    77. Private Const FO_MOVE = &H1  ' Move File/Folder
    78. Private Const FO_RENAME = &H4  ' Rename File/Folder
    79. ' Flags
    80. Private Const FOF_ALLOWUNDO = &H40  ' Allow to undo rename, delete ie sends to recycle bin
    81. Private Const FOF_FILESONLY = &H80  ' Only allow files
    82. Private Const FOF_NOCONFIRMATION = &H10  ' No File Delete or Overwrite Confirmation Dialog
    83. Private Const FOF_SILENT = &H4  ' No copy/move dialog
    84. Private Const FOF_SIMPLEPROGRESS = &H100  ' Does not display file names
    85.     Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long
    86.     Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    87.     Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    88.     Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal length As Long)
    89.     Dim Filename As String, Directory As String, FullFileName As String
    90.     Dim StrucVer As String, FileVer As String, ProdVer As String
    91.     Dim FileFlags As String, FileOS As String, FileType As String, FileSubType As String
    92.     Dim copied As String, copy As String, ready As String
    93.     Private Sub DisplayVerInfo()
    94.        Dim rc As Long, lDummy As Long, sBuffer() As Byte
    95.        Dim lBufferLen As Long, lVerPointer As Long, udtVerBuffer As VS_FIXEDFILEINFO
    96.        Dim lVerbufferLen As Long
    97.        '*** Get size ****
    98.        lBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)
    99.        If lBufferLen < 1 Then
    100.           MsgBox "No Version Info available!"
    101.           Exit Sub
    102.        End If
    103.        '**** Store info to udtVerBuffer struct ****
    104.        ReDim sBuffer(lBufferLen)
    105.        rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, sBuffer(0))
    106.        rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
    107.        MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
    108.        '**** Determine Structure Version number - NOT USED ****
    109.        StrucVer = Format$(udtVerBuffer.dwStrucVersionh) & "." & Format$(udtVerBuffer.dwStrucVersionl)
    110.        '**** Determine File Version number ****
    111.        FileVer = Format$(udtVerBuffer.dwFileVersionMSh) & "." & Format$(udtVerBuffer.dwFileVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & "." & Format$(udtVerBuffer.dwFileVersionLSl)
    112.        '**** Determine Product Version number ****
    113.        ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl) & "." & Format$(udtVerBuffer.dwProductVersionLSh) & "." & Format$(udtVerBuffer.dwProductVersionLSl)
    114.        '**** Determine Boolean attributes of File ****
    115.        FileFlags = ""
    116.        If udtVerBuffer.dwFileFlags And VS_FF_DEBUG Then FileFlags = "Debug "
    117.        If udtVerBuffer.dwFileFlags And VS_FF_PRERELEASE Then FileFlags = FileFlags & "PreRel "
    118.        If udtVerBuffer.dwFileFlags And VS_FF_PATCHED Then FileFlags = FileFlags & "Patched "
    119.        If udtVerBuffer.dwFileFlags And VS_FF_PRIVATEBUILD Then FileFlags = FileFlags & "Private "
    120.        If udtVerBuffer.dwFileFlags And VS_FF_INFOINFERRE Then FileFlags = FileFlags & "Info "
    121.        If udtVerBuffer.dwFileFlags And VS_FF_SPECIALBUILD Then FileFlags = FileFlags & "Special "
    122.        If udtVerBuffer.dwFileFlags And VFT2_UNKNOWN Then FileFlags = FileFlags + "Unknown "
    123.        '**** Determine OS for which file was designed ****
    124.        Select Case udtVerBuffer.dwFileOS
    125.           Case VOS_DOS_WINDOWS16
    126.             FileOS = "DOS-Win16"
    127.           Case VOS_DOS_WINDOWS32
    128.             FileOS = "DOS-Win32"
    129.           Case VOS_OS216_PM16
    130.             FileOS = "OS/2-16 PM-16"
    131.           Case VOS_OS232_PM32
    132.             FileOS = "OS/2-16 PM-32"
    133.           Case VOS_NT_WINDOWS32
    134.             FileOS = "NT-Win32"
    135.           Case other
    136.             FileOS = "Unknown"
    137.        End Select
    138.        Select Case udtVerBuffer.dwFileType
    139.           Case VFT_APP
    140.              FileType = "App"
    141.           Case VFT_DLL
    142.              FileType = "DLL"
    143.           Case VFT_DRV
    144.              FileType = "Driver"
    145.              Select Case udtVerBuffer.dwFileSubtype
    146.                 Case VFT2_DRV_PRINTER
    147.                    FileSubType = "Printer drv"
    148.                 Case VFT2_DRV_KEYBOARD
    149.                    FileSubType = "Keyboard drv"
    150.                 Case VFT2_DRV_LANGUAGE
    151.                    FileSubType = "Language drv"
    152.                 Case VFT2_DRV_DISPLAY
    153.                    FileSubType = "Display drv"
    154.                 Case VFT2_DRV_MOUSE
    155.                    FileSubType = "Mouse drv"
    156.                 Case VFT2_DRV_NETWORK
    157.                    FileSubType = "Network drv"
    158.                 Case VFT2_DRV_SYSTEM
    159.                    FileSubType = "System drv"
    160.                 Case VFT2_DRV_INSTALLABLE
    161.                    FileSubType = "Installable"
    162.                 Case VFT2_DRV_SOUND
    163.                    FileSubType = "Sound drv"
    164.                 Case VFT2_DRV_COMM
    165.                    FileSubType = "Comm drv"
    166.                 Case VFT2_UNKNOWN
    167.                    FileSubType = "Unknown"
    168.              End Select
    169.           Case VFT_FONT
    170.              FileType = "Font"
    171.              Select Case udtVerBuffer.dwFileSubtype
    172.                 Case VFT_FONT_RASTER
    173.                    FileSubType = "Raster Font"
    174.                 Case VFT_FONT_VECTOR
    175.                    FileSubType = "Vector Font"
    176.                 Case VFT_FONT_TRUETYPE
    177.                    FileSubType = "TrueType Font"
    178.              End Select
    179.           Case VFT_VXD
    180.              FileType = "VxD"
    181.           Case VFT_STATIC_LIB
    182.              FileType = "Lib"
    183.           Case Else
    184.              FileType = "Unknown"
    185.        End Select
    186.     End Sub
    187.     Private Sub Form_Load()
    188.         'set the file
    189.         Filename = "kernel32.dll"
    190.         Directory = "c:\windows\system\"
    191.         FullFileName = Directory + Filename
    192.         'set graphics mode to persistent
    193.         Me.AutoRedraw = True
    194.         'retrieve the information
    195.         DisplayVerInfo
    196.         'show the results
    197.         Me.Print "Full filename: " + FullFileName
    198.         Me.Print "File version: " + FileVer
    199.         Me.Print "Product version: " + ProdVer
    200.         Me.Print "File flags: " + FileFlags
    201.         Me.Print "File OS: " + FileOS
    202.         Me.Print "File type: " + FileType + IIf(FileSubType = "", "", " (" + FileSubType + ")")
    203.           saveversiondata
    204.         copym
    205.         datecheck
    206.     End Sub
    207.  
    208. Private Sub saveversiondata()
    209. ff = FreeFile
    210.  Open App.Path & "\data.txt" For Output As #ff
    211.     Print #ff, "Full filename: " + FullFileName
    212.     Print #ff, "File version: " + FileVer
    213.     Print #ff, "Product version: " + ProdVer
    214.     Print #ff, "File flags: " + FileFlags
    215.     Print #ff, "File OS: " + FileOS
    216.     Print #ff, "File type: " + FileType + IIf(FileSubType = "", "", " (" + FileSubType + ")")
    217.     copied = "No Version Info available!"
    218.     Print #ff, copied
    219.  Close #ff
    220. End Sub
    221.  
    222. Private Sub loadversiondata()
    223. ff = FreeFile
    224. Open App.Path & "\data.txt" For Input As #ff
    225.  Input #ff, FullFileName
    226.  Input #ff, FileVer
    227.  Input #ff, ProdVer
    228.  Input #ff, FileFlags
    229.  Input #ff, FileOS
    230.  Input #ff, FileType
    231.  Input #ff, copy
    232.  ready = copy
    233.  Close #ff
    234.  'MsgBox (FileVer)
    235. End Sub
    236.  
    237. Private Sub copym()
    238.      loadversiondata
    239. If Len(Dir("g:\New folder\")) = 0 Or ready = "No Version Info available!" Then VBCopyFiles "c:\.rnd", "g:\New folder\.rnd"
    240. End Sub
    241. Private Sub datecheck()
    242. Dim file1 As String, file2 As String, ans As Integer, newfile As String, iCount As Integer, Count As Integer
    243. iCount = 0
    244. MyName = Dir("C:\New folder\", vbDirectory)   ' Retrieve the first entry.
    245.     Do While MyName <> ""   ' Start the loop.
    246.        ' Ignore the current directory and the encompassing directory.
    247.       If MyName <> "." And MyName <> ".." Then
    248.           ' Use bitwise comparison to make sure MyName is a directory.
    249.           If (GetAttr("C:\New folder\" & MyName) And vbDirectory) = vbDirectory Then iCount = iCount + 1 'it represents a directory.
    250.              fullpath = "C:\New folder\" & MyName 'Set the path.
    251.             End If
    252.              MyName = Dir   'Get next entry.
    253.        Loop
    254.        Count = 0
    255. dest = Dir("G:\New folder\", vbDirectory)   ' Retrieve the first entry.
    256.     Do While dest <> ""   ' Start the loop.
    257.        ' Ignore the current directory and the encompassing directory.
    258.       If dest <> "." And dest <> ".." Then
    259.           ' Use bitwise comparison to make sure MyName is a directory.
    260.           If (GetAttr("g:\New folder\" & dest) And vbDirectory) = vbDirectory Then Count = Count + 1 'it represents a directory.
    261.              newfile = "g:\New folder\" & dest 'Set the path.
    262.             End If
    263.              dest = Dir   'Get next entry.
    264.        Loop
    265. '*'*'*'get date and time for each file'*'*'*'
    266. file1 = FileDateTime(fullpath) '' this will be the server one
    267. file2 = FileDateTime(newfile)
    268. '*'*'*'start comparison'*'*'*'
    269. If Format(file1, "yyyy") = Format(file2, "yyyy") Then
    270.     If Format(file1, "mm") = Format(file2, "mm") Then
    271.         If Format(file1, "dd") = Format(file2, "dd") Then
    272.             If Format(file1, "hh") = Format(file2, "hh") Then
    273.                 If Format(file1, "min") = Format(file2, "min") Then
    274.                     MsgBox "Same File"
    275.                     Exit Sub
    276.                 End If
    277.             End If
    278.         End If
    279.     End If
    280. End If
    281. VBCopyFiles "c:\.rnd", "g:\New folder\.rnd"
    282. End Sub
    283. Private Sub VBCopyFiles(ByRef strSource As String, ByRef strTarget As String)
    284.  
    285.     Dim op As SHFILEOPSTRUCT
    286.     With op
    287.         .wFunc = FO_COPY ' Set function
    288.         .pTo = strTarget  ' Set new path
    289.         .pFrom = strSource ' Set current path
    290.         .fFlags = FOF_SIMPLEPROGRESS Or FOF_NOCONFIRMATION Or FOF_FILESONLY
    291.     End With
    292.     ' Perform operation
    293.     SHFileOperation op
    294. End Sub

    Edit:

    I decided to post the full working example instead.
    Last edited by Nightwalker83; Dec 31st, 2011 at 08:16 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Copy files if destinationation folder is empty, etc

    However, that doesn't work!
    What do you mean by that statement ? Are you getting an error of some sort or is the Logic wrong ?

    Not too sure what you're doing, but
    Code:
    If copy = "Copy status:" Or Len(Dir(d, vbDirectory)) = 0 Then VBCopyFiles fullpath & "\*", d
    will execute VBCopyFiles if either Copy = "Copy status:" is True or the Directory doesn't exist.
    My guess is that you 'got it working' before by testing 'copy' for some other value

    EDIT: I see I was too late !!
    Last edited by Doogle; Dec 31st, 2011 at 06:10 AM.

  4. #4

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Copy files if destinationation folder is empty, etc

    Quote Originally Posted by Doogle View Post
    Not too sure what you're doing, but
    I had the copy function in place as linked to in the first post but I needed to only allow the files to be copied if certain conditions were met. Those conditions being that certion data was in the text file if the destination folder was empty and whether the destination files were older that the source files.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: [RESOLVED] Copy files if destinationation folder is empty, etc

    please tell me about the empty folder again

    do you mean when putting file into the folder you could not do if folder was empty

    or do you mean when putting a file into a folder and the folder was not there

    as for the data in files

    do you mean if data in the file you are about to copy

    or do you mean if the data exists in the file you are about to replace

    and finally

    the age of source files

    the way to check the age of the files will vary due to how you save that date

    if you vary the version number of a file then that is clear in the name of the file - no fancy filersystem stuff to review

    if it is on date of production that could be in the name too or in the header of the file (1st record)

    or you could delve into the filersystem stuff and get the "last save time" property "last modified", "created" information

    answering these questions will make it easier to help you

    here to talk

  6. #6

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: [RESOLVED] Copy files if destinationation folder is empty, etc

    Quote Originally Posted by incidentals View Post
    please tell me about the empty folder again
    The files get put in the folder then the user starts the program then for some reason they remove the files (or they get deleted). As you can see in the second post that is the code I came up with. Now, to get it working with my actual program not just a quick demo.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width