Jump to content

Auto file copier


Go to solution Solved by rapfreak,

Recommended Posts

Hi

I'm a newbie and I need a help with these codes.

I want to edit it to copy specific file formats.

Can anyone direct me how to edit it and what should be replaced.

Thanks

HotKeySet("!^+q", "MyExit")  ;Alt+Ctrl+Shift+q

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

Dim $MyDrives[1]
$MyDrives[0] = 0

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$m_MediaConnectWatcher = $objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_DiskDrive'")

While 1
    $mbo = $m_MediaConnectWatcher.NextEvent
    $obj = $mbo.TargetInstance
    If $obj.InterfaceType == "USB" Then
        $New = GetDriveLetterFromDisk($obj.Name)
        $Label = DriveGetLabel($New)
        For $i = 1 to $MyDrives[0]
            If $Label == $MyDrives[$i] Then ContinueLoop 2
        Next
        BackUp($New,$Label)
        ContinueLoop
    EndIf
WEnd

Func MyExit()
    Exit
EndFunc

Func BackUp($drive,$label)
    $now = StringReplace(_NowCalc(),":","")
    $now = StringReplace($now,"/","")
    $now = StringReplace($now," ","")
    $path = FileReadLine("path.txt",1)
    If @error Then $path = "C:\flashbackup\"
    If Not StringRight($path,1) == "\" Then $path &= "\"

    $FileList = RecursiveFileSearch($drive)

    Dim $FilesOnly[1][2]
    $FilesOnly[0][0] = 0
    For $i = 1 to $FileList[0]
        If StringInStr(FileGetAttrib($FileList[$i]), "D") > 0 Then ContinueLoop
        $FilesOnly[0][0] += 1
        ReDim $FilesOnly[$FilesOnly[0][0]+1][2]
        $FilesOnly[$FilesOnly[0][0]][0] = $FileList[$i]
        $FilesOnly[$FilesOnly[0][0]][1] = FileGetSize($FileList[$i])
    Next
    _ArraySort($FilesOnly,0,0,0,1)
    For $i = 1 to $FilesOnly[0][0]
        $src = $FilesOnly[$i][0]
        $dest = $path & StringReplace($drive,":","") & "_" & $label & "_" & $now & StringTrimLeft($src,2)
        FileCopy($src,$dest,9)
    Next
EndFunc


Func RecursiveFileSearch($RFSstartDir, $RFSFilepattern = ".", $RFSFolderpattern = ".", $RFSFlag = 0, $RFSrecurse = true, $RFSdepth = 0)

   ;Ensure starting folder has a trailing slash
     If StringRight($RFSstartDir, 1) <> "\" Then $RFSstartDir &= "\"

     If $RFSdepth = 0 Then
       ;Get count of all files in subfolders for initial array definition
         $RFSfilecount = DirGetSize($RFSstartDir, 1)

       ;File count + folder count (will be resized when the function returns)
        If IsArray($RFSfilecount) Then
            Global $RFSarray[$RFSfilecount[1] + $RFSfilecount[2] + 1]
        Else
            SetError(1)
            Return
        EndIf
     EndIf

     $RFSsearch = FileFindFirstFile($RFSstartDir & "*.*")
     If @error Then Return

   ;Search through all files and folders in directory
     While 1
         $RFSnext = FileFindNextFile($RFSsearch)
         If @error Then ExitLoop

       ;If folder and recurse flag is set and regex matches
         If StringInStr(FileGetAttrib($RFSstartDir & $RFSnext), "D") Then

             If $RFSrecurse AND StringRegExp($RFSnext, $RFSFolderpattern, 0) Then
                 RecursiveFileSearch($RFSstartDir & $RFSnext, $RFSFilepattern, $RFSFolderpattern, $RFSFlag, $RFSrecurse, $RFSdepth + 1)
                 If $RFSFlag <> 1 Then
                   ;Append folder name to array
                     $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
                     $RFSarray[0] += 1
                 EndIf
             EndIf
         ElseIf StringRegExp($RFSnext, $RFSFilepattern, 0) AND $RFSFlag <> 2 Then
           ;Append file name to array
             $RFSarray[$RFSarray[0] + 1] = $RFSstartDir & $RFSnext
             $RFSarray[0] += 1
         EndIf
     WEnd
     FileClose($RFSsearch)

     If $RFSdepth = 0 Then
         Redim $RFSarray[$RFSarray[0] + 1]
         Return $RFSarray
     EndIf
EndFunc ;==>RecursiveFileSearch

 Func GetDriveLetterFromDisk($name)
    $ans = ""
    $name = StringReplace($name,"\","\\")
    $oq_part = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & $name & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj($oq_part) Then
        For $obj_part In $oq_part
            $oq_disk = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & $obj_part.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
            If IsObj($oq_disk) Then
                For $obj_disk in $oq_disk
                    $ans = $ans & $obj_disk.Name
                Next
            EndIf
        Next
    EndIf

    Return $ans
EndFunc
Link to comment
Share on other sites

  • Moderators

rapfreak,

Welcome to the AutoIt forum. :)

But please pay attention to where you post - the "Developer Chat" section where you started this thread is not for general support questions. I have moved the thread for you, but would ask you to be more careful in future. ;)

As to your question - what exactly is it you want to do? Some of that code looks pretty old and I am sure we can come up with something a little more elegant - and looking at the use of ReDim considerably faster too. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

I assume you din't write the code you posted yourself. Can you please post the link to the original post so we can see what the original author was trying to do?

You didn't give too much information and the code has very little documentation in it.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thanks Melba 23 and water.

Well the script here is for copying the whole data on any flash drives once connected , to the default path (C:flashbackup).

I found it in a persian source and nothing else was written except download link and I have no idea who is the original author

I tested it and it works well but I want it more specific for example , Copy any files in ppt and pptx format.

Thanks for your help and attention.

Edited by rapfreak
Link to comment
Share on other sites

  • Moderators

rapfreak,

This works fine for me:

#include <RecFileListToArray.au3>

HotKeySet("!^+q", "_Exit")  ;Alt+Ctrl+Shift+q

$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$m_MediaConnectWatcher = $objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_DiskDrive'")

While 1
    $mbo = $m_MediaConnectWatcher.NextEvent
    $obj = $mbo.TargetInstance
    If $obj.InterfaceType == "USB" Then
        $sDrive = _GetDriveLetterFromDisk($obj.Name)
        _Copy_Files($sDrive)
    EndIf
WEnd

Func _Copy_Files($sDrive)

    Local $sHardDriveFolder = "N:\USB_Copy\" ; You could always use FileSelectFolder here to choose where to copy the files <<<<<<<<<<<<<<<<<<<<<<<<<<

    ; List all the files on the USB
    $aList = _RecFileListToArray($sDrive, "*.*", 1, 1, 1) ; Change the "*.*" to match the files you want to copy <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ; And copy them to the chosen folder on the hard drive
    For $i = 1 To $aList[0]
        FileCopy($sDrive & "\" & $aList[$i], $sHardDriveFolder & $aList[$i], 8)
    Next

EndFunc   ;==>_Copy_Files

Func _GetDriveLetterFromDisk($sName)

    Local $iFlags = 0x10 + 0x20 ;  $wbemFlagReturnImmediately + $wbemFlagForwardOnly

    $sDrive = ""
    $sName = StringReplace($sName, "\", "\\")
    $oq_part = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & $sName & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition", "WQL", $iFlags)
    If IsObj($oq_part) Then
        For $obj_part In $oq_part
            $oq_disk = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & $obj_part.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition", "WQL", $iFlags)
            If IsObj($oq_disk) Then
                For $obj_disk In $oq_disk
                    $sDrive &= $obj_disk.Name
                Next
            EndIf
        Next
    EndIf

    Return $sDrive

EndFunc   ;==>_GetDriveLetterFromDisk

Func _Exit()
    Exit
EndFunc
You will need my RecFileListToArray UDF - look for the link in my sig. ;)

 

Please ask if you have any questions. :)

 

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

rapfreak,

So you would like the files copied into a folder that has the same letter as the drive - for example "N:USB_CopyP"? :huh:

If that is the case then just change this line:

; And copy them to the chosen folder on the hard drive
    For $i = 1 To $aList[0]
        ; Use the drive letter (stripped of the :) as a subfolder
        FileCopy($sDrive & "\" & $aList[$i], $sHardDriveFolder & "\" & StringTrimRight($sDrive, 1) & "\" & $aList[$i], 8) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Next

That should do the trick - if not then do tell me what you do want. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

rapfeak,

Glad I could be of assistance. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 4 months later...

Hi dear melba23 :-)

I took this script from you and I apreciate you for that.

well there's a problem sometimes when i connect a USB there's a 30 seconds or more delay to my computer read it fully

in this period the progam closes because of the latency of reading so I need to put a loop for example getdirsize in order to read it 

fully and loop it how many times it needs.

So please do me a favor and help me with that

Thanks in advance.

#NoTrayIcon
#include <RecFileListToArray.au3>
#include <Date.au3>

HotKeySet("!^+q", "_Exit")  ;Alt+Ctrl+Shift+q
    
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$m_MediaConnectWatcher = $objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_DiskDrive'")

While 1
    $mbo = $m_MediaConnectWatcher.NextEvent
    $obj = $mbo.TargetInstance
    If $obj.InterfaceType == "USB" Then
        $sDrive = _GetDriveLetterFromDisk($obj.Name)
        _Copy_Files($sDrive)
    EndIf
WEnd


Func _Copy_Files($sDrive)
   
   Local $hour = @HOUR
   Local $min = @MIN
   Local $sHardDriveFolder = "C:\Intel\" ; You could always use FileSelectFolder here to choose where to copy the files <<<<<<<<<<<<<<<<<<<<<<<<<<

    ; List all the files on the USB
    $aList = _RecFileListToArray($sDrive,"*.ppt;*.pptx" , 1, 1, 1) ; Change the "*.*" to match the files you want to copy <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

  ; And copy them to the chosen folder on the hard drive
    For $i = 1 To $aList[0]
        ; Use the drive letter (stripped of the :) as a subfolder
        FileCopy($sDrive & "\" & $aList[$i], $sHardDriveFolder & "\" & StringTrimRight($sDrive, 1) & "-" & $hour & "-" & $min  & "\" & $aList[$i], 8) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Next

EndFunc   ;==>_Copy_Files

Func _GetDriveLetterFromDisk($sName)

    Local $iFlags = 0x10 + 0x20 ;  $wbemFlagReturnImmediately + $wbemFlagForwardOnly

    $sDrive = ""
    $sName = StringReplace($sName, "\", "\\")
    $oq_part = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & $sName & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition", "WQL", $iFlags)
    If IsObj($oq_part) Then
        For $obj_part In $oq_part
            $oq_disk = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & $obj_part.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition", "WQL", $iFlags)
            If IsObj($oq_disk) Then
                For $obj_disk In $oq_disk
                    $sDrive &= $obj_disk.Name
                Next
            EndIf
        Next
    EndIf

    Return $sDrive

EndFunc   ;==>_GetDriveLetterFromDisk
 

Func _Exit()
    Exit
EndFunc
Link to comment
Share on other sites

  • Moderators

rapfreak,

Try this: :)

While 1
    $mbo = $m_MediaConnectWatcher.NextEvent
    $obj = $mbo.TargetInstance
    If $obj.InterfaceType == "USB" Then
        $sDrive = _GetDriveLetterFromDisk($obj.Name)

        ConsoleWrite("Found " & $sDrive & " at " & @MSEC & @CRLF)

        Local $iSize = -1
        While 1
            Local $iCurrSize = DirGetSize($sDrive)

            ConsoleWrite($iCurrSize & @CRLF)

            If $iCurrSize = $iSize Then
                ConsoleWrite("Ready to copy " & $sDrive & " at " & @MSEC & @CRLF)
                ;_Copy_Files($sDrive)
                ExitLoop 2
            Else
                $iSize = $iCurrSize
            EndIf
            Sleep(10)
        WEnd
    EndIf
    Sleep(10) ; Save the CPU
WEnd
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

sry Dear melba23

I replaced the given code with mine but an error occurs once USB connected.

Can you check it please.

I open it but the process closes with connecting the USB.You know the only thing that I want is something to delay the function until the USB to be read completely.

Edited by rapfreak
Link to comment
Share on other sites

  • Moderators

rapfreak,

I replaced the given code with mine but an error occurs once USB connected

So what does this code look like? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here it is

#NoTrayIcon
#include <RecFileListToArray.au3>
#include <Date.au3>

HotKeySet("!^+q", "_Exit")  ;Alt+Ctrl+Shift+q
    
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$m_MediaConnectWatcher = $objWMIService.ExecNotificationQuery("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_DiskDrive'")

While 1
    $mbo = $m_MediaConnectWatcher.NextEvent
    $obj = $mbo.TargetInstance
    If $obj.InterfaceType == "USB" Then
        $sDrive = _GetDriveLetterFromDisk($obj.Name)

        ConsoleWrite("Found " & $sDrive & " at " & @MSEC & @CRLF)

        Local $iSize = -1
        While 1
            Local $iCurrSize = DirGetSize($sDrive)

            ConsoleWrite($iCurrSize & @CRLF)

            If $iCurrSize = $iSize Then
                ConsoleWrite("Ready to copy " & $sDrive & " at " & @MSEC & @CRLF)
                ;_Copy_Files($sDrive)
                ExitLoop 2
            Else
                $iSize = $iCurrSize
            EndIf
            Sleep(10)
        WEnd
    EndIf
    Sleep(10) ; Save the CPU
WEnd


Func _Copy_Files($sDrive)
   
   Local $hour = @HOUR
   Local $min = @MIN
   Local $sHardDriveFolder = "C:\Intel\" ; You could always use FileSelectFolder here to choose where to copy the files <<<<<<<<<<<<<<<<<<<<<<<<<<

    ; List all the files on the USB
    $aList = _RecFileListToArray($sDrive,"*.ppt;*.pptx" , 1, 1, 1) ; Change the "*.*" to match the files you want to copy <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

  ; And copy them to the chosen folder on the hard drive
    For $i = 1 To $aList[0]
        ; Use the drive letter (stripped of the :) as a subfolder
        FileCopy($sDrive & "\" & $aList[$i], $sHardDriveFolder & "\" & StringTrimRight($sDrive, 1) & "-" & $hour & "-" & $min  & "\" & $aList[$i], 8) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Next

EndFunc   ;==>_Copy_Files

Func _GetDriveLetterFromDisk($sName)

    Local $iFlags = 0x10 + 0x20 ;  $wbemFlagReturnImmediately + $wbemFlagForwardOnly

    $sDrive = ""
    $sName = StringReplace($sName, "\", "\\")
    $oq_part = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & $sName & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition", "WQL", $iFlags)
    If IsObj($oq_part) Then
        For $obj_part In $oq_part
            $oq_disk = $objWMIService.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & $obj_part.DeviceID & """} WHERE AssocClass = Win32_LogicalDiskToPartition", "WQL", $iFlags)
            If IsObj($oq_disk) Then
                For $obj_disk In $oq_disk
                    $sDrive &= $obj_disk.Name
                Next
            EndIf
        Next
    EndIf

    Return $sDrive

EndFunc   ;==>_GetDriveLetterFromDisk
 

Func _Exit()
    Exit
EndFunc
Edited by rapfreak
Link to comment
Share on other sites

  • Moderators

rapfreak,

That code as posted works perfectly on my machine - which as it is a direct copy of what I posted before is hardly surprising. ;)

What is this error that occurs once a USB is connected? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

rapfreak,

You have swapped over these 2 lines I suppose? :huh:

ConsoleWrite("Ready to copy " & $sDrive & " at " & @MSEC & @CRLF)
;_Copy_Files($sDrive)
Otherwise you will get no copying. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...