06. juni 2002 - 13:42Der er
4 kommentarer og 3 løsninger
Drivelistbox - en haster derfor 100 POINT
Hejsa Har lavet en drivelistbox, hvor den finder mine aktuelle drev. Den bruger jeg til noget kopiering. Problemet er bare at når jeg bruger denne, virker den fint ved alle de drev der ingen navne har. Men hvis drev C f.eks. hedder SPil, ja så oprettes først en mappe der hedder spil, og herefter kopieres de rigtige ting ind. Men hvis DrevC ikke hedder noget, virker det som det skal. Kan man sætte en property på drivelistbox'en så den ikke viser navne, blot selve drev-bogstavet.
Private Sub Command1_Click() Dim Path As String Path = App.Path If Right$(" " & Path, 1) <> "\" Then ' Ser efter at der IKKE er en backslash til slut Path = Path & "\" ' ... og tilføjer den i så fald End If Shell "xcopy """ & Path & "da*.*"" """ & Drive1.Drive & "\common\*.*"" /C /I /Y", vbHide MsgBox "Installation er fuldført - Afslut nu programmet" End Sub
'-------------------------------- Module1 -------------------------------- Public Declare Function SHFileOperation Lib _ "shell32.dll" Alias "SHFileOperationA" _ (lpFileOp As Any) As Long
Public Declare Sub SHFreeNameMappings Lib _ "shell32.dll" (ByVal hNameMappings As Long)
Public Declare Sub CopyMemory Lib "KERNEL32" _ Alias "RtlMoveMemory" (hpvDest As Any, hpvSource _ As Any, ByVal cbCopy As Long)
Public Type SHFILEOPSTRUCT hwnd As Long wFunc As FO_Functions pFrom As String pTo As String fFlags As FOF_Flags fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String End Type
Public Enum FO_Functions FO_MOVE = &H1 FO_COPY = &H2 FO_DELETE = &H3 FO_RENAME = &H4 End Enum
Public Type SHNAMEMAPPING pszOldPath As String pszNewPath As String cchOldPath As Long cchNewPath As Long End Type
Public Function SHFileOP(ByRef lpFileOp As SHFILEOPSTRUCT) As Long Dim result As Long Dim lenFileop As Long Dim foBuf() As Byte lenFileop = LenB(lpFileOp) ReDim foBuf(1 To lenFileop) Call CopyMemory(foBuf(1), lpFileOp, lenFileop) Call CopyMemory(foBuf(19), foBuf(21), 12) result = SHFileOperation(foBuf(1)) SHFileOP = result End Function
Public Function sCopy(sFile1, sFile2) 'Kopier filer eller mapper Dim lret As Long Dim fileop As SHFILEOPSTRUCT With fileop .hwnd = 0 .wFunc = FO_COPY .pFrom = sFile1 .pTo = sFile2 .lpszProgressTitle = "Fra: " & sFile1 & " Til: " & sFile2 .fFlags = FOF_SIMPLEPROGRESS Or FOF_RENAMEONCOLLISION End With lret = SHFileOP(fileop) If result <> 0 Then MsgBox Err.LastDllError Else If fileop.fAnyOperationsAborted <> 0 Then MsgBox "Operation Failed" End If End If End Function
Public Function sDelete(sFile) 'Slette filer eller mapper Dim lret As Long Dim fileop As SHFILEOPSTRUCT With fileop .hwnd = 0 .wFunc = FO_DELETE .pFrom = sFile .lpszProgressTitle = sFile1 .fFlags = FOF_SIMPLEPROGRESS Or FOF_ALLOWUNDO End With lret = SHFileOP(fileop) If result <> 0 Then MsgBox Err.LastDllError Else If fileop.fAnyOperationsAborted <> 0 Then MsgBox "Operation Failed" End If End If End Function
Public Function sRename(sFile1, sFile2) 'Omdøbe filer eller mapper Dim lret As Long Dim fileop As SHFILEOPSTRUCT With fileop .hwnd = 0 .wFunc = FO_RENAME .pFrom = sFile1 .pTo = sFile2 .lpszProgressTitle = "Fra: " & sFile1 & " Til: " & sFile2 .fFlags = FOF_SIMPLEPROGRESS Or FOF_ALLOWUNDO End With lret = SHFileOP(fileop) If result <> 0 Then MsgBox Err.LastDllError Else If fileop.fAnyOperationsAborted <> 0 Then MsgBox "Operation Failed" End If End If End Function
Public Function sMove(sFile1, sFile2) 'Flytte filer eller mapper Dim lret As Long Dim fileop As SHFILEOPSTRUCT With fileop .hwnd = 0 .wFunc = FO_MOVE .pFrom = sFile1 .pTo = sFile2 .lpszProgressTitle = "Fra: " & sFile1 & " Til: " & sFile2 .fFlags = FOF_SIMPLEPROGRESS Or FOF_ALLOWUNDO End With lret = SHFileOP(fileop) If result <> 0 Then MsgBox Err.LastDllError Else If fileop.fAnyOperationsAborted <> 0 Then MsgBox "Operation Failed" End If End If End Function '-------------------------------- Module1 --------------------------------
Private Sub Command1_Click() 'sMove "C:\Temp\TestFile.txt", "C:\" sMove "C:\TestMappe", "C:\Temp" End Sub
Private Sub Command3_Click() 'sCopy "D:\TestFile.txt", "C:\" sCopy "F:\*.*", "C:\Temp\Test" End Sub
Private Sub Command4_Click() 'sDelete "C:\TestFile.txt" sDelete "C:\TestMappe" End Sub
Private Sub Command5_Click() 'sRename "C:\Ejay_se.zip", "C:\Ejay_se.zip_" sRename "C:\TestMappe", "C:\TestMappe2" End Sub
'-------------------------- hvis du skal kopier flere filer -------------------------- 'sCopy "D:\ser.htm" & vbNullChar & "D:\test.htm", "C:\" '-------------------------- hvis du skal kopier flere filer --------------------------
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.