rapfreak

Auto file copier

36 posts in this topic

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

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thank you very much.That was so useful.

Share this post


Link to post
Share on other sites

I think there is a problem with the last function I tested it but it doesn't make a folder the same name with the USB drive letter it just copy them to default folder.

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

You helped me too much.Thanks a lot.

Share this post


Link to post
Share on other sites

rapfeak,

Glad I could be of assistance. :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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
1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Dear melba23

thanks a lot  :sweating:

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

rapfreak,

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

So what does this code look like? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Dear Melba23

Nothing happens by connecting my USB and progam closes in windows processes once I connect one.

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

so what should I do?

Share this post


Link to post
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