Oppure

Loading
29/04/11 10:24
The Real Dummie
eh lo so, lo so... e' un titolo del cavolo, pero' non saprei come porlo diversamente :-(
per prima cosa i miei saluti e poi una domanda:

devo copiare su chiavetta usb dei file ma non so a quale lettera corrisponda la chiavetta. per di piu' potrei avere piu' periferiche inserite e pertanto dovrei copiarlo su tutte. non mi preoccupa poi piu' di tanto se i file venissero copiati anche su i vari dischi fissi presenti sui pc.

la domanda e' questa: esiste un metodo per aprire un ciclo tipo for next che valga per le varie lettere dell'alfabeto? in questo modo io scriverei poche righe per indurre la copiatura su tutte le possibili usb inserite. ovviamente con un bel on error... eviterei di essere interroto per i drive mancanti.

chiedo scusa per il linguaggio poco tecnico, ma dummie ero e dummie saro' a vita :-(((

un bel saluto a tutti ma soprattutto grazie
TRD
aaa
29/04/11 13:39
fusebyte
Mi intrometto,..tanto fra dummies..:-)
Non sarebbe meglio riuscire a trovare la precisa lettera del drive giusto?

Ciao
aaa
29/04/11 13:56
Sal47
Ciao, forse potrebbe esserti utile il listato seguente che io utilizzo per una esigenza analoga alla tua
(nel mio caso copio il file Form1.jpg dal desktop alla chiavetta USB che nel mio PC ha la lettera H,
e con il ciclo for...next che ho aggiunto funziona per tutte le periferiche, da C a P ad esempio):
________________________________
Option Explicit

Private Sub Command1_Click()
On Error Resume Next
Dim chiavetta, n
' * * ricavato da "I Trucchi di VB6, F. Balena";)
Dim fs, dc
Set fs = CreateObject("Scripting.FileSystemObject";)
Set dc = fs.Drives
' * *
For n = 67 To 80 ' codice ASCII dalla lettera C alla lettera P
chiavetta = Chr$(n)
' per copiare una cartella con tutti i files in essa contenuti
'fs.CopyFolder "c:\...", "chiavetta:\", True
' e per copiare singoli file (True:> sovrascrive il file nel caso esistesse già;)
fs.CopyFile "C:\...\Desktop\Form1.jpg", chiavetta & ":\", True
Next n

End Sub
____________________
Fammi sapere se il listato risolve il problema. Saluti
aaa
30/04/11 10:29
PcBase
Ciao

Provate col seguente codice a trovare la lettera della chiave USB:
Attenzione! occorre impostare il riferimento

' requires a reference to the Microsoft Scripting Runtime library:
' Tools, References, Microsoft Scripting Runtime C:\WINDOWS\system32\Scrrun.dll

Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long

Dim volName As String
Dim VolSerialNumber As Variant 'Long
Dim VolMaxName As Long
Dim VolFlag As Long
Dim VolSysName As String
Public Drive As Variant


Sub ListAllDrives()
' requires a reference to the Microsoft Scripting Runtime library:
' Tools, References, Microsoft Scripting Runtime  C:\WINDOWS\system32\Scrrun.dll
Const StartRow As Long = 1
Dim fso As Scripting.FileSystemObject, drv As Scripting.Drive, r As Long, c As Long
    Set fso = New Scripting.FileSystemObject
    ' list drives
    For Each drv In fso.Drives
        With drv
            If .DriveType = Removable Then
                If .DriveLetter = "A" Then
                ElseIf .DriveLetter = "B" Then
                Else
                    r = r + 1
                    If .IsReady Then
                        If .TotalSize >= 4194304 Then
                            Testo = Testo & .DriveLetter & Chr(13) & Format(.TotalSize / 1048576, "##,##0") & " Mb" & Chr(13) & _
                            Format(.FreeSpace / 1048576, "##,##0") & " Mb" & Chr(13) & _
                            Format((.TotalSize - .FreeSpace) / 1048576, "##,##0") & " Mb" & Chr(13)
                        Else
                            Testo = Testo & .DriveLetter & Chr(13) & Format(.TotalSize / 1024, "##,##0") & " Kb" & Chr(13) & _
                            Format(.FreeSpace / 1024, "##,##0") & " Kb" & Chr(13) & _
                            Format((.TotalSize - .FreeSpace) / 1024, "##,##0") & " Mb" & Chr(13)
                        End If
                        Testo = Testo & .FileSystem & Chr(13)
                    End If
                    VolSerialNumber = 0
                    GetVolumeInformation (.DriveLetter & ":\"), String$(200, 0), Len(String$(200, 0)), VolSerialNumber, VolMaxName, VolFlag, String$(200, 0), Len(String$(200, 0))
                    If Not VolSerialNumber = 0 Then
                        Testo = Testo & VolSerialNumber & Chr(13) & Chr(13)
                    End If
                End If
            End If
        End With
    Next drv
    Set drv = Nothing
    Set fso = Nothing
    MsgBox Testo
End Sub
Ultima modifica effettuata da PcBase 30/04/11 11:44
aaa