 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
xueying608
Joined: 16 Jun 2009 Posts: 4
|
Posted: Tue Jun 16, 2009 4:00 am Post subject: Files&folders Search---A more efficient script |
|
|
I wrote a file search program.
Any suggestions or requests are appreciated.
More powerful searching tools, i suggest,are everything and Locate32.
hehe!
| Code: |
#SingleInstance
#NoTrayIcon
SetBatchLines,-1
height=200
Gui +Resize
Gui,Add, Edit, x10 y10 h25 w400 vInput
Gui, Add, BUTTON,x420 w55 h25 yp-0 gInputEvent,Search
Gui, Add, BUTTON,x480 w60 h25 yp-0 vtoggle gsuspendEvent,Suspend
Gui, Add, BUTTON,x545 w55 h25 yp-0 gstopEvent,Stop
Gui, Add, Button, x+10 h25 gButtonSwitchView, SwitchView
Gui, Add, GroupBox, x10 y35 w600 h30 vgb1
Gui,Add,Text,x20 y50,Please choose the Drive:
DriveGet, fixedDrives, List, fixed
DriveGet, REMOVABLEDrives, List,REMOVABLE
allDrives = %fixedDrives%%REMOVABLEDrives%
Loop, Parse, allDrives
{
if %A_LoopField%=
Gui, Add, Checkbox,x%height% y50 v%A_LoopField% checked, (%A_LoopField%:)
height +=50
}
Gui, Add, GroupBox,x10 w600 h30 vgb2
Gui,Add,Text,x20 y85,Please choose the type:
Gui, Add, Radio,x+10 yp-0 vfile,File only
Gui, Add, Radio,x+10 yp-0 vfolder,Folder only
Gui, Add, Radio, x+10 yp-0 vfilefolder checked,File & Folder
Gui,Add, ListView, x10 w600 r40 vMyListView gMyListView grid -Hdr,Name|In Folder
;LV_ModifyCol(3, "Integer")
ImageListID1 := IL_Create(10)
ImageListID2 := IL_Create(10, 10, true) ; A list of large icons to go with the small ones.
LV_SetImageList(ImageListID1)
LV_SetImageList(ImageListID2)
guicontrol,,c,0
Menu, MyContextMenu, Add, Open, ContextOpenFile
Menu, MyContextMenu, Add, Cut, ContextmoveFile
Menu, MyContextMenu, Add, Copy, ContextcopyFile
Menu, MyContextMenu, Add, Delete, ContextdeleteFile
Menu, MyContextMenu, Add, Properties, ContextProperties
Menu, MyContextMenu, Add,
Menu, MyContextMenu, Add, Find target file, Contextfindtarget
Menu, MyContextMenu, Add, Remove from ListView, ContextClearRows
Menu, MyContextMenu, Default, Open
Gui, Color, E8E8FF
Gui,Show,,Everywhere【bingbing出品】
return
GuiClose:
GuiEscape:
ExitApp
ButtonSwitchView:
if not IconView
GuiControl, +Icon, MyListView ; Switch to icon view.
else
GuiControl, +Report, MyListView ; Switch back to details view.
IconView := not IconView ; Invert in preparation for next time.
return
suspendEvent:
GuiControlGet,toggle,,, Text
if toggle=Suspend
{
GuiControl, , toggle ,Continue
}
else
{
GuiControl, , toggle ,Suspend
}
Pause,,1
return
stopEvent:
flag=0
GuiControl,Enable,button1
type=
return
InputEvent:
GuiControl,Disable,button1
SetBatchLines,-1
flag=1
Gui +OwnDialogs
gui,submit
if file
{
type=0
}
if folder
{
type=2
}
if filefolder
{
type=1
}
VarSetCapacity(Filename, 260)
sfi_size = 352
VarSetCapacity(sfi, sfi_size)
GuiControl, -Redraw, MyListView
gui,show
GuiControlGet, Input
LV_Delete()
Loop, Parse, allDrives
{
if %A_LoopField%=1
{
Loop, %A_LoopField%:\*%Input%*.*,%type%,1
{ if flag=1
{
FileName := A_LoopFileFullPath
SplitPath, FileName,,, FileExt
if FileExt in EXE,ICO,ANI,CUR
{
ExtID := FileExt
IconNumber = 0
}
else
{
ExtID = 0
Loop 7
{
StringMid, ExtChar, FileExt, A_Index, 1
if not ExtChar
break
ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1)))
}
IconNumber := IconArray%ExtID%
}
if not IconNumber
{
if not DllCall("Shell32\SHGetFileInfoA", "str", FileName, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101)
IconNumber = 9999999
else
{
hIcon = 0
Loop 4
hIcon += *(&sfi + A_Index-1) << 8*(A_Index-1)
IconNumber := DllCall("ImageList_ReplaceIcon", "uint", ImageListID1, "int", -1, "uint", hIcon) + 1
DllCall("ImageList_ReplaceIcon", "uint", ImageListID2, "int", -1, "uint", hIcon)
DllCall("DestroyIcon", "uint", hIcon)
IconArray%ExtID% := IconNumber
}
}
LV_Add("Icon" . IconNumber, A_LoopFileName, A_LoopFileDir)
GuiControl, +Redraw, MyListView
LV_ModifyCol()
LV_ModifyCol(3, 60)
}
else
{
break
}
}
}
}
type=
GuiControl,Enable,button1
Return
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(FileName, A_EventInfo, 1) ; Get the text of the first field.
LV_GetText(FileDir, A_EventInfo, 2) ; Get the text of the second field.
Run %FileDir%\%FileName%,, UseErrorLevel
if ErrorLevel
MsgBox Could not open "%FileDir%\%FileName%".
}
Return
GuiContextMenu:
if A_GuiControl <> MyListView
return
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return
ContextOpenFile:
ContextProperties:
FocusedRowNumber := LV_GetNext(0, "F")
if not FocusedRowNumber
return
LV_GetText(FileName, FocusedRowNumber,1)
LV_GetText(Filedir, FocusedRowNumber,2)
IfInString A_ThisMenuItem, Open
Run %FileDir%\%FileName%,, UseErrorLevel
else
Run Properties "%FileDir%\%FileName%",, UseErrorLevel
if ErrorLevel
MsgBox Could not perform requested action on "%FileName%".
return
ContextClearRows:
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
if not RowNumber
break
LV_Delete(RowNumber)
}
return
ContextmoveFile:
FileSelectFolder, Folder,, 3, Choose a folder to Paste:
if not Folder
return
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
LV_GetText(FileName, RowNumber,1)
LV_GetText(Filedir, RowNumber,2)
txt=%FileDir%\%FileName%
property:= FileExist(txt)
IfNotInString,property,d
{
Filemove,%FileDir%\%FileName%,%folder%,1
}
else
{
ToolTip ,***************************`n* *`n* *`n* Moving。。。。 *`n* *`n* *`n***************************, X400, Y100
FilemoveDir,%FileDir%\%FileName%, %folder%\%FileName%,1
tooltip
msgbox,Complete!
}
if not RowNumber
{
Progress, Off
break
}
LV_Delete(RowNumber)
}
return
ContextcopyFile:
FileSelectFolder, Folder,, 3, Choose a folder to Paste:
if not Folder
return
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
LV_GetText(FileName, RowNumber,1)
LV_GetText(Filedir, RowNumber,2)
txt=%FileDir%\%FileName%
property:= FileExist(txt)
IfNotInString,property,d
{
Filecopy,%FileDir%\%FileName%,%folder%,1
}
else
{
ToolTip ,***************************`n* *`n* *`n* Copying。。。。 *`n* *`n* *`n***************************, X400, Y100
FileCopyDir,%FileDir%\%FileName%, %folder%\%FileName%,1
tooltip
msgbox,Complete!
}
if not RowNumber
{
Progress, Off
break
}
LV_Delete(RowNumber)
}
return
ContextdeleteFile:
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
LV_GetText(FileName, RowNumber,1)
LV_GetText(Filedir, RowNumber,2)
txt=%FileDir%\%FileName%
property:= FileExist(txt)
IfNotInString,property,d
{
Filedelete,%FileDir%\%FileName%
}
else
{
ToolTip ,***************************`n* *`n* *`n* deleting。。。。 *`n* *`n* *`n***************************, X400, Y100
FileRemoveDir,%FileDir%\%FileName%,1
ToolTip
msgbox,Complete!
}
if not RowNumber
{
Progress, Off
break
}
LV_Delete(RowNumber)
}
return
Contextfindtarget:
FocusedRowNumber := LV_GetNext(0, "F")
if not FocusedRowNumber
return
LV_GetText(FileName, FocusedRowNumber,1)
LV_GetText(Filedir, FocusedRowNumber,2)
txt=%FileDir%\%FileName%
Run, % "explorer.exe /e,/select," . Txt
if ErrorLevel
msgbox,Cannot find %Txt%
return
GuiSize:
if A_EventInfo = 1
return
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
GuiControl, Move, gb1, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
GuiControl, Move, gb2, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
return
|
_________________ xueying608
Last edited by xueying608 on Tue Jun 16, 2009 8:37 am; edited 1 time in total |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 941 Location: Germany - Deutschland
|
Posted: Tue Jun 16, 2009 8:03 am Post subject: |
|
|
Thank you very much. Could you please write the text in English, so I understand the Buttons? Thanx a lot!
Greets, aaffe |
|
| Back to top |
|
 |
xueying608
Joined: 16 Jun 2009 Posts: 4
|
Posted: Tue Jun 16, 2009 8:38 am Post subject: |
|
|
| aaffe wrote: | Thank you very much. Could you please write the text in English, so I understand the Buttons? Thanx a lot!
Greets, aaffe |
ok,i have changed. _________________ xueying608 |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 941 Location: Germany - Deutschland
|
Posted: Tue Jun 16, 2009 11:24 am Post subject: |
|
|
Thank you!
Greets, aaffe |
|
| Back to top |
|
 |
Drugwash
Joined: 07 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Wed Jun 17, 2009 6:20 pm Post subject: |
|
|
| One note after having looked through your script: according to my recent experience, SHGetFileInfoA might have some leak, at least under Win9x. I've been working on a script that uses this function and after 10,000 or so iterations, it corrupts the GDI layer and eventually crashes the script. Your mileage may vary though. |
|
| Back to top |
|
 |
aaffe
Joined: 17 May 2007 Posts: 941 Location: Germany - Deutschland
|
Posted: Mon Jul 06, 2009 9:35 am Post subject: |
|
|
Hallo,
I´ve changed the script a bit, so you can choose an special folder where to search the files and/or folders instead of the drive-names:
| Code: |
#SingleInstance
#NoTrayIcon
SetBatchLines,-1
height=200
Verz:="C:\"
Gui +Resize
Gui,Add, Edit, x10 y10 h25 w400 vInput
Gui, Add, BUTTON,x420 w55 h25 yp-0 gInputEvent,Search
Gui, Add, BUTTON,x480 w60 h25 yp-0 vtoggle gsuspendEvent,Suspend
Gui, Add, BUTTON,x545 w55 h25 yp-0 gstopEvent,Stop
Gui, Add, Button, x+10 h25 gButtonSwitchView, SwitchView
Gui, Add, GroupBox, x10 y35 w600 h30 vgb1
Gui,Add,Text,x110 y55 w450 vVerzeichnis,Selected Folder: %Verz%
Gui, Add, Button, x20 y50 gFolders,Change Folder
/*
DriveGet, fixedDrives, List, fixed
DriveGet, REMOVABLEDrives, List,REMOVABLE
allDrives = %fixedDrives%%REMOVABLEDrives%
Loop, Parse, allDrives
{
if %A_LoopField%=
Gui, Add, Checkbox,x%height% y50 v%A_LoopField% checked, (%A_LoopField%:)
height +=50
}
*/
Gui, Add, GroupBox,x10 w600 h30 vgb2
Gui,Add,Text,x20 y85,Please choose the type:
Gui, Add, Radio,x+10 yp-0 vfile,File only
Gui, Add, Radio,x+10 yp-0 vfolder,Folder only
Gui, Add, Radio, x+10 yp-0 vfilefolder checked,File & Folder
Gui,Add, ListView, x10 w600 r40 vMyListView gMyListView grid -Hdr,Name|In Folder
;LV_ModifyCol(3, "Integer")
ImageListID1 := IL_Create(10)
ImageListID2 := IL_Create(10, 10, true) ; A list of large icons to go with the small ones.
LV_SetImageList(ImageListID1)
LV_SetImageList(ImageListID2)
guicontrol,,c,0
Menu, MyContextMenu, Add, Open, ContextOpenFile
Menu, MyContextMenu, Add, Cut, ContextmoveFile
Menu, MyContextMenu, Add, Copy, ContextcopyFile
Menu, MyContextMenu, Add, Delete, ContextdeleteFile
Menu, MyContextMenu, Add, Properties, ContextProperties
Menu, MyContextMenu, Add,
Menu, MyContextMenu, Add, Find target file, Contextfindtarget
Menu, MyContextMenu, Add, Remove from ListView, ContextClearRows
Menu, MyContextMenu, Default, Open
Gui, Color, E8E8FF
Gui,Show,,Everywhere?bingbing???
return
GuiClose:
GuiEscape:
ExitApp
Folders:
FileSelectFolder,Verz,*%Verz%
GuiControl,,Verzeichnis,Selected Folder: %Verz%
Return
ButtonSwitchView:
if not IconView
GuiControl, +Icon, MyListView ; Switch to icon view.
else
GuiControl, +Report, MyListView ; Switch back to details view.
IconView := not IconView ; Invert in preparation for next time.
return
suspendEvent:
GuiControlGet,toggle,,, Text
if toggle=Suspend
{
GuiControl, , toggle ,Continue
}
else
{
GuiControl, , toggle ,Suspend
}
Pause,,1
return
stopEvent:
flag=0
GuiControl,Enable,button1
type=
return
InputEvent:
GuiControl,Disable,button1
SetBatchLines,-1
flag=1
Gui +OwnDialogs
gui,submit
if file
{
type=0
}
if folder
{
type=2
}
if filefolder
{
type=1
}
VarSetCapacity(Filename, 260)
sfi_size = 352
VarSetCapacity(sfi, sfi_size)
GuiControl, -Redraw, MyListView
gui,show
Gui, Submit,Nohide
GuiControlGet, Input
LV_Delete()
/*
Loop, Parse, allDrives
{
if %A_LoopField%=1
{
*/
Loop, %Verz%\*%Input%*.*,%type%,1
/*
{ if flag=1
*/
{
FileName := A_LoopFileFullPath
SplitPath, FileName,,, FileExt
if FileExt in EXE,ICO,ANI,CUR
{
ExtID := FileExt
IconNumber = 0
}
else
{
ExtID = 0
Loop 7
{
StringMid, ExtChar, FileExt, A_Index, 1
if not ExtChar
break
ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1)))
}
IconNumber := IconArray%ExtID%
}
if not IconNumber
{
if not DllCall("Shell32\SHGetFileInfoA", "str", FileName, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101)
IconNumber = 9999999
else
{
hIcon = 0
Loop 4
hIcon += *(&sfi + A_Index-1) << 8*(A_Index-1)
IconNumber := DllCall("ImageList_ReplaceIcon", "uint", ImageListID1, "int", -1, "uint", hIcon) + 1
DllCall("ImageList_ReplaceIcon", "uint", ImageListID2, "int", -1, "uint", hIcon)
DllCall("DestroyIcon", "uint", hIcon)
IconArray%ExtID% := IconNumber
}
}
LV_Add("Icon" . IconNumber, A_LoopFileName, A_LoopFileDir)
GuiControl, +Redraw, MyListView
LV_ModifyCol()
LV_ModifyCol(3, 60)
}
/* else
{
break
}
}
}
}
*/
type=
GuiControl,Enable,button1
Return
MyListView:
if A_GuiEvent = DoubleClick
{
LV_GetText(FileName, A_EventInfo, 1) ; Get the text of the first field.
LV_GetText(FileDir, A_EventInfo, 2) ; Get the text of the second field.
Run %FileDir%\%FileName%,, UseErrorLevel
if ErrorLevel
MsgBox Could not open "%FileDir%\%FileName%".
}
Return
GuiContextMenu:
if A_GuiControl <> MyListView
return
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return
ContextOpenFile:
ContextProperties:
FocusedRowNumber := LV_GetNext(0, "F")
if not FocusedRowNumber
return
LV_GetText(FileName, FocusedRowNumber,1)
LV_GetText(Filedir, FocusedRowNumber,2)
IfInString A_ThisMenuItem, Open
Run %FileDir%\%FileName%,, UseErrorLevel
else
Run Properties "%FileDir%\%FileName%",, UseErrorLevel
if ErrorLevel
MsgBox Could not perform requested action on "%FileName%".
return
ContextClearRows:
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
if not RowNumber
break
LV_Delete(RowNumber)
}
return
ContextmoveFile:
FileSelectFolder, Folder,, 3, Choose a folder to Paste:
if not Folder
return
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
LV_GetText(FileName, RowNumber,1)
LV_GetText(Filedir, RowNumber,2)
txt=%FileDir%\%FileName%
property:= FileExist(txt)
IfNotInString,property,d
{
Filemove,%FileDir%\%FileName%,%folder%,1
}
else
{
ToolTip ,***************************`n* *`n* *`n* Moving???? *`n* *`n* *`n***************************, X400, Y100
FilemoveDir,%FileDir%\%FileName%, %folder%\%FileName%,1
tooltip
msgbox,Complete!
}
if not RowNumber
{
Progress, Off
break
}
LV_Delete(RowNumber)
}
return
ContextcopyFile:
FileSelectFolder, Folder,, 3, Choose a folder to Paste:
if not Folder
return
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
LV_GetText(FileName, RowNumber,1)
LV_GetText(Filedir, RowNumber,2)
txt=%FileDir%\%FileName%
property:= FileExist(txt)
IfNotInString,property,d
{
Filecopy,%FileDir%\%FileName%,%folder%,1
}
else
{
ToolTip ,***************************`n* *`n* *`n* Copying???? *`n* *`n* *`n***************************, X400, Y100
FileCopyDir,%FileDir%\%FileName%, %folder%\%FileName%,1
tooltip
msgbox,Complete!
}
if not RowNumber
{
Progress, Off
break
}
LV_Delete(RowNumber)
}
return
ContextdeleteFile:
RowNumber = 0
Loop
{
RowNumber := LV_GetNext(RowNumber - 1)
LV_GetText(FileName, RowNumber,1)
LV_GetText(Filedir, RowNumber,2)
txt=%FileDir%\%FileName%
property:= FileExist(txt)
IfNotInString,property,d
{
Filedelete,%FileDir%\%FileName%
}
else
{
ToolTip ,***************************`n* *`n* *`n* deleting???? *`n* *`n* *`n***************************, X400, Y100
FileRemoveDir,%FileDir%\%FileName%,1
ToolTip
msgbox,Complete!
}
if not RowNumber
{
Progress, Off
break
}
LV_Delete(RowNumber)
}
return
Contextfindtarget:
FocusedRowNumber := LV_GetNext(0, "F")
if not FocusedRowNumber
return
LV_GetText(FileName, FocusedRowNumber,1)
LV_GetText(Filedir, FocusedRowNumber,2)
txt=%FileDir%\%FileName%
Run, % "explorer.exe /e,/select," . Txt
if ErrorLevel
msgbox,Cannot find %Txt%
return
GuiSize:
if A_EventInfo = 1
return
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
GuiControl, Move, gb1, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
GuiControl, Move, gb2, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
return
|
Greets, aaffe |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|