Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

Показать сообщение отдельно

Старожил


Сообщения: 440
Благодарности: 12

Профиль | Отправить PM | Цитировать


подумал что в моем случае логичней убивать не дерево, а просто процессы путь в которым ведет на флэшку.
для получения буквы диска я хотел использовать примерно следующий код, только в цикле.

Дак вот он работает только с теми приложениями у которых удается корректно получить путь. Путь к explorer.exe почему-то выдается как А , и в той части где происходит выделение из пути диска происходит ошибка.

Мне надо как-то отфильтровать неподходящие значения перед передачей в _PathSplitByRegExp , но в случае вообще пустых значений пути у меня не получилось.

Код: Выделить весь код
#include <File.au3>
#include <Array.au3>
#include <GUIListView.au3>

Local $PID = ProcessExists("explorer.exe")

MsgBox(0, '', '-' & $PID & '-')

Local $path = _ProcessGetLocation($PID)

MsgBox(0, '1$path', '|' & $path & '|')

MsgBox(0, '', VarGetType($path))

MsgBox(0, '2', $path)

Local $drive = _PathSplitByRegExp($path)

MsgBox(0, '2', $drive[1])




;===============================================================================
; Function Name:    _PathSplitByRegExp()
; Description:      Split the path to 8 elements.
; Parameter(s):     $sPath - Path to split.
; Requirement(s):  
; Return Value(s):  On seccess - Array $aRetArray that contain 8 elements:
;                   $aRetArray[0] = Full path ($sPath)
;                   $aRetArray[1] = Drive letter
;                   $aRetArray[2] = Path without FileName and extension
;                   $aRetArray[3] = Full path without File Extension
;                   $aRetArray[4] = Full path without drive letter
;                   $aRetArray[5] = FileName and extension
;                   $aRetArray[6] = Just Filename
;                   $aRetArray[7] = Just Extension of a file
;
;                   On failure - If $sPath not include correct path (the path is not splitable),
;                   then $sPath returned.
;                   If $sPath not include needed delimiters, or it's emty,
;                   then @error set to 1, and returned -1.
;
; Note(s):          The path can include backslash as well (exmp: C:/test/test.zip).
;
; Author(s):        G.Sandler a.k.a CreatoR (MsCreatoR) - Thanks to amel27 for help with RegExp
;===============================================================================
Func _PathSplitByRegExp($sPath)
    If $sPath = "" Or (StringInStr($sPath, "\") And StringInStr($sPath, "/")) Then Return SetError(1, 0, -1)
   
    Local $aRetArray[8], $pDelim = ""
   
    If StringRegExp($sPath, '^(?i)([A-Z]:|\\)(\\[^\\]+)+$') Then $pDelim = "\"
    If StringRegExp($sPath, '(?i)(^.*:/)(/[^/]+)+$') Then $pDelim = "//"
   
    If $pDelim = "" Then $pDelim = "/"
    If Not StringInStr($sPath, $pDelim) Then Return $sPath
    If $pDelim = "\" Then $pDelim &= "\"
   
    $aRetArray[0] = $sPath ;Full path
    $aRetArray[1] = StringRegExpReplace($sPath,  $pDelim & '.*', $pDelim) ;Drive letter
    $aRetArray[2] = StringRegExpReplace($sPath, $pDelim & '[^' & $pDelim & ']*$', '') ;Path without FileName and extension
    $aRetArray[3] = StringRegExpReplace($sPath, '\.[^.]*$', '') ;Full path without File Extension
    $aRetArray[4] = StringRegExpReplace($sPath, '(?i)([A-Z]:' & $pDelim & ')', '') ;Full path without drive letter
    $aRetArray[5] = StringRegExpReplace($sPath, '^.*' & $pDelim, '') ;FileName and extension
    $aRetArray[6] = StringRegExpReplace($sPath, '.*' & $pDelim & '|\.[^.]*$', '') ;Just Filename
    $aRetArray[7] = StringRegExpReplace($sPath, '^.*\.', '') ;Just Extension of a file
   
    Return $aRetArray
EndFunc


Func _ProcessGetLocation($iPID)
     Local $aProc = DllCall('kernel32.dll', 'hwnd', 'OpenProcess', 'int', BitOR(0x0400, 0x0010), 'int', 0, 'int', $iPID)
     If $aProc[0] = 0 Then Return SetError(1, 0, '')
     Local $vStruct = DllStructCreate('int[1024]')
     DllCall('psapi.dll', 'int', 'EnumProcessModules', 'hwnd', $aProc[0], 'ptr', DllStructGetPtr($vStruct), 'int', DllStructGetSize($vStruct), 'int_ptr', 0)
     Local $aReturn = DllCall('psapi.dll', 'int', 'GetModuleFileNameEx', 'hwnd', $aProc[0], 'int', DllStructGetData($vStruct, 1), 'str', '', 'int', 2048)
     If StringLen($aReturn[3]) = 0 Then Return SetError(2, 0, '')
     Return $aReturn[3]
EndFunc

Отправлено: 01:33, 24-02-2012 | #4