Что нового

Как в ListView отображать имя файла, а при выделение имя файла с полным путем

StarEdik

Новичок
Сообщения
365
Репутация
4
Привет всем !
Прошу помочь мне. Скрипт находить файлы и загружает их в ListView .В ListView отображается имя файла с полным путем к файлу.При выделении файла в ListView на Label-e тоже выводиться имя файла с полным путем .Это отображение на Label-e используется для запуска файла. Все хорошо, но мне нужен чтоб в ListView - е отображался только имя файла а в Label-e имя файла с полным путем.
Код:
;Поиск файлов Результаты поиска
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Global $iIndexOld = -10
Global $FileSource,$FileList, $FilList,$aItems,$iI,$sText,$Pr1,$P2, $Pr3
#Region ### START Koda GUI section ### Form=E:\Proqramlar\Auto_It\AutoIt_Forms\Поиск .au3 файлов_ver1.kxf
$Form1 = GUICreate("Поиск .au3 файлов", 251, 597, @DesktopWidth-260, @DesktopHeight-690)
$Input1 = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples\Helpfile\", 3, 4, 217, 21)
$BtSelFolder = GUICtrlCreateButton("...", 223, 3, 25, 23)
$LblFileName = GUICtrlCreateLabel("Путь и Имя Файла", 5, 25, 230, 47,$SS_Left)
$ListView1 = GUICtrlCreateListView("", 0, 68, 249, 447)
$ListView1 = GUICtrlGetHandle($ListView1)
     _GUICtrlListView_AddColumn($ListView1, "Результаты поиска AutoIt файлов", 244)
$BtRun = GUICtrlCreateButton("Run", 5, 524, 76, 25)
$BtSciTE = GUICtrlCreateButton("SciTE", 87, 524, 76, 25)
$BtExit = GUICtrlCreateButton("Exit", 184, 561, 59, 25)
$BtDeltoRECYCLER = GUICtrlCreateButton("Удалить в корзину", 71, 561, 108, 25)
$BtSearch = GUICtrlCreateButton("Найти", 171, 525, 73, 24)
$BtMove = GUICtrlCreateButton("Move", 6, 561, 59, 25)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE , $BtExit
			Exit
        Case $BtSearch
             _SearchFiles()
		Case $BtRun
             ;
		Case $BtSciTE
             ;
		Case $BtDeltoRECYCLER
			  _GUICtrlListView_DeleteAllItems($ListView1)

	EndSwitch
WEnd
Func _SearchFiles()

	 $FileSource = GUICtrlRead($Input1)
	 $FileMask="*.au3"
	  Local $aItems[2500][1]
			$FileList = _FileSearch($FileSource, $FileMask)
			If Not @error Then
			   For $i = 1 To $FileList[0]
                  $aItems[$i][0] =$FileList[$i]
			   Next
		   EndIf
         _GUICtrlListView_DeleteAllItems($ListView1)
	_GUICtrlListView_AddArray($ListView1, $aItems)

EndFunc


Func _FileSearch($s_Path_Search, $s_File_Mask = '*', $i_Flag = 0, $i_SubDir = 1);1

    Local $s_Out, $a_Out, $s_Read, $h_Dir, $s_Attrib, $s_Subdir, $a_Masks

    If StringRight($s_Path_Search, 1) == '\' Then ;нужно, если $s_Path_Search - диск (например C:\)
        $s_Path_Search = StringTrimRight($s_Path_Search, 1)
    EndIf
    If $i_SubDir Then
        $s_Subdir = ' /S /B'
    Else
        $s_Subdir = ' /B'
    EndIf
    Switch $i_Flag
        Case 1
            $s_Attrib = ' /A-D'
        Case 2
            $s_Attrib = ' /AD'
        Case Else
            $s_Attrib = ' /A'
    EndSwitch
    $s_Out = StringToBinary('0' & @CRLF, 2)
    $a_Masks = StringSplit($s_File_Mask, ';')
    For $i = 1 To $a_Masks[0]
        $h_Dir = Run(@ComSpec & ' /U /C DIR "' & $s_Path_Search & '\' & $a_Masks[$i] & '"' & $s_Subdir & $s_Attrib, @SystemDir, @SW_HIDE, 6)
        If Not $h_Dir Then Return SetError(1)
        While 1
            $s_Read = StdoutRead($h_Dir, False, True)
            If @error Then
                ExitLoop
            EndIf
            If $s_Read Then
                $s_Out &= $s_Read
            EndIf
            Sleep(10)
        WEnd
    Next
    $a_Out = StringRegExp(BinaryToString($s_Out, 2), '[^\r\n]+', 3)
    If @error Then Return SetError(1)
    $a_Out[0] = UBound($a_Out) - 1
    Return $a_Out
EndFunc   ;==>_FileSearch

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode, $tInfo, $iIndexNow, $sNewText,$Pr,$Pr2
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
    $iCode = DllStructGetData($tNMHDR, 'Code')

    Switch $hWndFrom
        Case $ListView1
            Switch $iCode
                Case $LVN_ITEMCHANGING
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $iIndexNow = DllStructGetData($tInfo, 'Index')
                    If $iIndexOld <> $iIndexNow Then
                        $iIndexOld = $iIndexNow
						GUICtrlSetData($LblFileName, _GUICtrlListView_GetItemText($ListView1, $iIndexOld))
						;$LblFileName =GUICtrlRead($Input1)
						;ConsoleWrite($LblFileName & @CRLF)

                    EndIf
                Case $NM_DBLCLK
					$LblFileName = GUICtrlRead($Input1)
					;ConsoleWrite($LblFileName  & @CRLF)
                    ;Run($LblFileName)

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 

Zaramot

I ♥ AutoIt
Сообщения
1,160
Репутация
660
Re: Как отображать имя файла в Lictview -е а полный путь с именем файла в Label-e

Код:
;Поиск файлов Результаты поиска
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Global $iIndexOld = -10
Global $FileSource,$FileList, $FilList,$aItems,$iI,$sText,$Pr1,$P2, $Pr3
#Region ### START Koda GUI section ### Form=E:\Proqramlar\Auto_It\AutoIt_Forms\Поиск .au3 файлов_ver1.kxf
$Form1 = GUICreate("Поиск .au3 файлов", 251, 597, @DesktopWidth-260, @DesktopHeight-690)
$Input1 = GUICtrlCreateInput("C:\Program Files\AutoIt3\Examples\Helpfile\", 3, 4, 217, 21)
$BtSelFolder = GUICtrlCreateButton("...", 223, 3, 25, 23)
$LblFileName = GUICtrlCreateLabel("Путь и Имя Файла", 5, 25, 230, 47,$SS_Left)
$ListView1 = GUICtrlCreateListView("", 0, 68, 249, 447)
$ListView1 = GUICtrlGetHandle($ListView1)
     _GUICtrlListView_AddColumn($ListView1, "Результаты поиска AutoIt файлов", 244)
$BtRun = GUICtrlCreateButton("Run", 5, 524, 76, 25)
$BtSciTE = GUICtrlCreateButton("SciTE", 87, 524, 76, 25)
$BtExit = GUICtrlCreateButton("Exit", 184, 561, 59, 25)
$BtDeltoRECYCLER = GUICtrlCreateButton("Удалить в корзину", 71, 561, 108, 25)
$BtSearch = GUICtrlCreateButton("Найти", 171, 525, 73, 24)
$BtMove = GUICtrlCreateButton("Move", 6, 561, 59, 25)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE , $BtExit
            Exit
        Case $BtSearch
             _SearchFiles()
        Case $BtRun
             ;
        Case $BtSciTE
             ;
        Case $BtDeltoRECYCLER
              _GUICtrlListView_DeleteAllItems($ListView1)

    EndSwitch
WEnd
Func _SearchFiles()
     $FileSource = GUICtrlRead($Input1)
     $FileMask="*.au3"
      Local $aItems[2500][1]
            $FileList = _FileSearch($FileSource, $FileMask)
            If Not @error Then
               For $i = 1 To $FileList[0]
;Добавлено
				   $Reg=StringRegExpReplace($FileList[$i], '(^.*)\\(.*)$', '\2') ;Выдергиваем из полного пути только имя c расширение файла.
                  $aItems[$i][0] =$Reg
               Next
           EndIf
         _GUICtrlListView_DeleteAllItems($ListView1)
    _GUICtrlListView_AddArray($ListView1, $aItems)

EndFunc


Func _FileSearch($s_Path_Search, $s_File_Mask = '*', $i_Flag = 0, $i_SubDir = 1);1

    Local $s_Out, $a_Out, $s_Read, $h_Dir, $s_Attrib, $s_Subdir, $a_Masks

    If StringRight($s_Path_Search, 1) == '\' Then ;нужно, если $s_Path_Search - диск (например C:\)
        $s_Path_Search = StringTrimRight($s_Path_Search, 1)
    EndIf
    If $i_SubDir Then
        $s_Subdir = ' /S /B'
    Else
        $s_Subdir = ' /B'
    EndIf
    Switch $i_Flag
        Case 1
            $s_Attrib = ' /A-D'
        Case 2
            $s_Attrib = ' /AD'
        Case Else
            $s_Attrib = ' /A'
    EndSwitch
    $s_Out = StringToBinary('0' & @CRLF, 2)
    $a_Masks = StringSplit($s_File_Mask, ';')
    For $i = 1 To $a_Masks[0]
        $h_Dir = Run(@ComSpec & ' /U /C DIR "' & $s_Path_Search & '\' & $a_Masks[$i] & '"' & $s_Subdir & $s_Attrib, @SystemDir, @SW_HIDE, 6)
        If Not $h_Dir Then Return SetError(1)
        While 1
            $s_Read = StdoutRead($h_Dir, False, True)
            If @error Then
                ExitLoop
            EndIf
            If $s_Read Then
                $s_Out &= $s_Read
            EndIf
            Sleep(10)
        WEnd
    Next
    $a_Out = StringRegExp(BinaryToString($s_Out, 2), '[^\r\n]+', 3)
    If @error Then Return SetError(1)
    $a_Out[0] = UBound($a_Out) - 1
    Return $a_Out
EndFunc   ;==>_FileSearch

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode, $tInfo, $iIndexNow, $sNewText,$Pr,$Pr2
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
    $iCode = DllStructGetData($tNMHDR, 'Code')

    Switch $hWndFrom
        Case $ListView1
            Switch $iCode
                Case $LVN_ITEMCHANGING
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    $iIndexNow = DllStructGetData($tInfo, 'Index')
                    If $iIndexOld <> $iIndexNow Then
                        $iIndexOld = $iIndexNow
                        GUICtrlSetData($LblFileName, GUICtrlRead($Input1) & _GUICtrlListView_GetItemText($ListView1, $iIndexOld)) ;Изменено
                        ;$LblFileName =GUICtrlRead($Input1)
                        ;ConsoleWrite($LblFileName & @CRLF)

                    EndIf
                Case $NM_DBLCLK
                    $LblFileName = GUICtrlRead($Input1)
                    ;ConsoleWrite($LblFileName  & @CRLF)
                    ;Run($LblFileName)

            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Re: Как отображать имя файла в Lictview -е а полный путь с именем файла в Label-e

StarEdik [?]
Нет такого элемента, это ListView.

И заголовок темы поправьте, непонятно что там изложено.
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
Re: Как отображать имя файла в Lictview -е а полный путь с именем файла в Label-e

StarEdik,
Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Global $iIndexOld = -10
Global $FileSource, $aFileList, $FileList, $FilList, $aItems, $iI, $sText, $Pr1, $P2, $Pr3
#region ### START Koda GUI section ### Form=E:\Proqramlar\Auto_It\AutoIt_Forms\Поиск .au3 файлов_ver1.kxf
$Form1 = GUICreate("Поиск .au3 файлов", 251, 597, @DesktopWidth - 260, @DesktopHeight - 690)
$Input1 = GUICtrlCreateInput(@DesktopDir, 3, 4, 217, 21)
$BtSelFolder = GUICtrlCreateButton("...", 223, 3, 25, 23)
$LblFileName = GUICtrlCreateLabel("Путь и Имя Файла", 5, 25, 230, 47, $SS_Left)
$ListView1 = GUICtrlCreateListView("", 0, 68, 249, 447)
$ListView1 = GUICtrlGetHandle($ListView1)
_GUICtrlListView_AddColumn($ListView1, "Результаты поиска AutoIt файлов", 244)
$BtRun = GUICtrlCreateButton("Run", 5, 524, 76, 25)
$BtSciTE = GUICtrlCreateButton("SciTE", 87, 524, 76, 25)
$BtExit = GUICtrlCreateButton("Exit", 184, 561, 59, 25)
$BtDeltoRECYCLER = GUICtrlCreateButton("Удалить в корзину", 71, 561, 108, 25)
$BtSearch = GUICtrlCreateButton("Найти", 171, 525, 73, 24)
$BtMove = GUICtrlCreateButton("Move", 6, 561, 59, 25)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
#endregion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE, $BtExit
			Exit
		Case $BtSearch
			_SearchFiles($aFileList)
	EndSwitch
WEnd
Func _SearchFiles(ByRef $a_FileList)
	Local $FileMask = "*.au3", $FileSource = GUICtrlRead($Input1), $aItems[1]
	$a_FileList = 0
	$a_FileList = _FileSearch($FileSource, $FileMask)
	If @error Then
		$a_FileList = 0
		Return
	EndIf
	ReDim $aItems[$a_FileList[0]][1]
	For $i = 1 To $a_FileList[0]
		$aItems[$i - 1][0] = StringRegExpReplace($a_FileList[$i], '^.*\\', '')
	Next
	_GUICtrlListView_BeginUpdate($ListView1)
	_GUICtrlListView_DeleteAllItems($ListView1)
	_GUICtrlListView_AddArray($ListView1, $aItems)
	_GUICtrlListView_EndUpdate($ListView1)
EndFunc   ;==>_SearchFiles


Func _FileSearch($sPath, $sFileMask = "*", $iFlag = 0, $iSubDir = 1, $iSort = 0)
	;CreatoR; http://autoit-script.ru/index.php/topic,8266.msg55775
	Local $sOutBin, $sOut, $aOut, $aMasks, $sRead, $hDir, $sAttrib, $sFiles

	If Not StringInStr(FileGetAttrib($sPath), "D") Then
		Return SetError(1, 0, 0)
	EndIf
	If $iSubDir = 1 Then
		$sAttrib &= ' /S'
	EndIf
	If $iSort = 1 Then
		$sAttrib &= ' /O:N'
	EndIf
	Switch $iFlag
		Case 1
			$sAttrib &= ' /A-D'
		Case 2
			$sAttrib &= ' /AD'
		Case Else
			$sAttrib &= ' /A'
	EndSwitch
	$sOut = StringToBinary('0' & @CRLF, 2)
	$sPath = StringRegExpReplace($sPath, '\\+$', '')
	$sFileMask = StringRegExpReplace($sFileMask, '^;+|;+$', '')
	$sFileMask = StringRegExpReplace($sFileMask, ';{2,}', ';')
	$aMasks = StringSplit($sFileMask, ';')
	For $i = 1 To $aMasks[0]
		If StringStripWS($aMasks[$i], 8) = "" Then
			ContinueLoop
		EndIf
		$sFiles &= '"' & $sPath & '\' & $aMasks[$i] & '"'
		If $i < $aMasks[0] Then
			$sFiles &= ';'
		EndIf
	Next
	$hDir = Run(@ComSpec & ' /U /C DIR ' & $sFiles & ' /B' & $sAttrib, @SystemDir, @SW_HIDE, 6)
	While 1
		$sRead = StdoutRead($hDir, False, True)
		If @error Then
			ExitLoop
		EndIf
		If $sRead <> "" Then
			$sOut &= $sRead
		EndIf
		Sleep(10)
	WEnd
	$aOut = StringRegExp(BinaryToString($sOut, 2), '[^\r\n]+', 3)
	If @error Or UBound($aOut) < 2 Then
		Return SetError(2, 0, 0)
	EndIf
	$aOut[0] = UBound($aOut) - 1
	Return $aOut
EndFunc   ;==>_FileSearch

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
	Local $tNMHDR, $hWndFrom, $iCode, $tInfo, $iIndexNow, $sNewText, $Pr, $Pr2
	$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
	$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
	$iCode = DllStructGetData($tNMHDR, 'Code')

	Switch $hWndFrom
		Case $ListView1
			Switch $iCode
				Case $LVN_ITEMCHANGED
					If IsArray($aFileList) Then
						$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
						$iIndexNow = DllStructGetData($tInfo, 'Index')
						If $iIndexOld <> $iIndexNow Then
							$iIndexOld = $iIndexNow
							GUICtrlSetData($LblFileName, $aFileList[$iIndexOld + 1])
						EndIf
					EndIf
				;Case $NM_DBLCLK
				;	$LblFileName = GUICtrlRead($Input1)
					;ConsoleWrite($LblFileName  & @CRLF)
					;Run($LblFileName)

			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
Автор
StarEdik

StarEdik

Новичок
Сообщения
365
Репутация
4
Zaramot
Спасибо.Одно но.
Если выбрать диск (например C:\) и найти все файлы ,то скрипт при выделении не показывает полный путь к файлу в Label.

madmasles
БОЛЬШОЕ спасибо вам.
CreatoR
ОК.
 
Верх