rapfreak Posted June 8, 2013 Share Posted June 8, 2013 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 expandcollapse popupHotKeySet("!^+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 More sharing options...
Moderators Melba23 Posted June 8, 2013 Moderators Share Posted June 8, 2013 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
water Posted June 8, 2013 Share Posted June 8, 2013 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 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
rapfreak Posted June 8, 2013 Author Share Posted June 8, 2013 (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 June 8, 2013 by rapfreak Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 8, 2013 Moderators Share Posted June 8, 2013 rapfreak,This works fine for me:expandcollapse popup#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 EndFuncYou 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
rapfreak Posted June 8, 2013 Author Share Posted June 8, 2013 Thank you very much.That was so useful. Link to comment Share on other sites More sharing options...
rapfreak Posted June 8, 2013 Author Share Posted June 8, 2013 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. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 8, 2013 Moderators Share Posted June 8, 2013 rapfreak, So you would like the files copied into a folder that has the same letter as the drive - for example "N:USB_CopyP"? 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
rapfreak Posted June 8, 2013 Author Share Posted June 8, 2013 You helped me too much.Thanks a lot. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 8, 2013 Moderators Share Posted June 8, 2013 rapfeak, Glad I could be of assistance. M23 rapfreak 1  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
rapfreak Posted October 19, 2013 Author Share Posted October 19, 2013 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. expandcollapse popup#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 More sharing options...
Moderators Melba23 Posted October 19, 2013 Moderators Share Posted October 19, 2013 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 WEndM23 rapfreak 1  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
rapfreak Posted October 19, 2013 Author Share Posted October 19, 2013 Dear melba23 thanks a lot Link to comment Share on other sites More sharing options...
rapfreak Posted October 19, 2013 Author Share Posted October 19, 2013 (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 October 19, 2013 by rapfreak Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 19, 2013 Moderators Share Posted October 19, 2013 rapfreak,I replaced the given code with mine but an error occurs once USB connectedSo what does this code look like? M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
rapfreak Posted October 19, 2013 Author Share Posted October 19, 2013 (edited) Here it is expandcollapse popup#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 October 19, 2013 by rapfreak Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 20, 2013 Moderators Share Posted October 20, 2013 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? M23  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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
rapfreak Posted October 20, 2013 Author Share Posted October 20, 2013 Dear Melba23 Nothing happens by connecting my USB and progam closes in windows processes once I connect one. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 20, 2013 Moderators Share Posted October 20, 2013 rapfreak,You have swapped over these 2 lines I suppose? 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
rapfreak Posted October 20, 2013 Author Share Posted October 20, 2013 so what should I do? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now