Ultratuga Posted August 27, 2014 Share Posted August 27, 2014 Hi everybody, I´m trying to create my first script. Here´s my first problem: in a folder I have 5 files: file1.ext.1 file1.ext.2 file1.ext.3 file2.ext.1 file2.ext.2 In "FileOpenDialog" function is it possible to filter the files just showing the following lines? file1.ext file2.ext I have to hide the numbers and then remove duplicates, I think. Any ideas? Thanks in advance. Jose. Link to comment Share on other sites More sharing options...
jguinch Posted August 27, 2014 Share Posted August 27, 2014 I think the native FileOpenDialog function cannot do what you want. You will have to build your own dialog box (GUI). Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
MikahS Posted August 27, 2014 Share Posted August 27, 2014 Pretty sure jguinch is right Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Ultratuga Posted August 28, 2014 Author Share Posted August 28, 2014 Too bad, that´s too much for a noob like me. My script dies here . Thank you for your answers, jguinch and MikahS. Link to comment Share on other sites More sharing options...
MikahS Posted August 29, 2014 Share Posted August 29, 2014 Anytime Ultra, nothing wrong with trying new things out Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
iamtheky Posted August 29, 2014 Share Posted August 29, 2014 How about just presenting the .1 files then acting on the return as necessary? If there is only a potential for single digit numbers no further logic is needed than. $selectedfile = fileopendialog("ext files" , @Scriptdir , "EXT(*.ext.1)") msgbox(0, '' , stringtrimright($selectedfile, 2)) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
kylomas Posted August 30, 2014 Share Posted August 30, 2014 ultratuga, If you want to "get wet" you can use this as a starting point... expandcollapse popup#include <ListBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <FileConstants.au3> #include <array.au3> #include <File.au3> #include <GuiListBox.au3> #AutoIt3Wrapper_Add_Constants=n ; ask for folder that contains the "*.ext.*" files $folder = FileSelectFolder('Select folder to process',"") ; using desktop as root folder if @error = 1 then exit ; create an array of the files in the selected folder that match the "*.ext.*" pattern $afiles = _FileListToArray($folder,'*.ext.*') switch @error case 1 msgbox(16,'*** ERROR ***','Folder not found or invalid') exit case 2 msgbox(16,'*** ERROR ***','Invalid Filter') exit case 3 msgbox(16,'*** ERROR ***','Invalid Flag') exit case 4 msgbox(16,'*** ERROR ***','No Files Found') exit endswitch ; create a string of base file names to populate the first listbox local $tStr = '', $tfile for $1 = 1 to $afiles[0] $tfile = StringRegExp($afiles[$1], "(.+)\.\w{1,5}$", 3)[0] if stringinstr($tStr, $tfile) = 0 then $tStr &= '|' & $tfile next ; setup the gui and populate the "base filename" listbox local $gui010 = guicreate('Custom File Lister') local $aSize = wingetclientsize($gui010) guictrlcreatelabel('Base Files',0,5,$aSize[0]/2-10,20,$SS_CENTER) guictrlcreatelabel('Duplicates',$aSize[0]/2+10,5,$aSize[0]/2-10,20,$SS_CENTER) local $lst010 = guictrlcreatelist('',0,20,$aSize[0]/2-10,$asize[1]-20,$ss_sunken) guictrlsetdata($lst010,$tstr) local $lst020 = guictrlcreatelist('',$aSize[0]/2+10,20,$aSize[0]/2-10,$asize[1]-20,$ss_sunken) local $dummy010 = guictrlcreatedummy() local $dummy020 = guictrlcreatedummy() guisetstate() ; register the command mssage processor GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") while 1 switch guigetmsg() case $gui_event_close Exit case $dummy010 ; actioned by _WM_COMMAND $tstr = '' for $1 = 1 to $afiles[0] if stringinstr($afiles[$1], _GUICtrlListBox_GetText($lst010,_GUICtrlListBox_GetCurSel($lst010))) > 0 then $tStr &= '|' & $afiles[$1] next guictrlsetdata($lst020,$tstr) case $dummy020 ; actioned by _WM_COMMAND msgbox(0,'Do Something with the File','File = ' & _GUICtrlListBox_GetText($lst020,_GUICtrlListBox_GetCurSel($lst020))) EndSwitch WEnd ; command processing routine ; monitors command messages for selection changes within either listbox and actions the appropriate control Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg switch $lParam case guictrlgethandle($lst010) switch BitShift($wParam, 16) case $LBN_SELCHANGE guictrlsendtodummy($dummy010) EndSwitch case guictrlgethandle($lst020) switch BitShift($wParam, 16) case $LBN_SELCHANGE guictrlsendtodummy($dummy020) EndSwitch endswitch EndFunc ;==>_WM_COMMAND kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Ultratuga Posted September 3, 2014 Author Share Posted September 3, 2014 How about just presenting the .1 files then acting on the return as necessary? If there is only a potential for single digit numbers no further logic is needed than. $selectedfile = fileopendialog("ext files" , @Scriptdir , "EXT(*.ext.1)") msgbox(0, '' , stringtrimright($selectedfile, 2)) Hi. I like your idea, but sometimes I have: file.ext file.ext.10 file.ext.1000 etc... The program starts with file.ext and saves a new file every time I save, incrementing extension. Link to comment Share on other sites More sharing options...
Ultratuga Posted September 3, 2014 Author Share Posted September 3, 2014 ultratuga, If you want to "get wet" you can use this as a starting point... expandcollapse popup#include <ListBoxConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <FileConstants.au3> #include <array.au3> #include <File.au3> #include <GuiListBox.au3> #AutoIt3Wrapper_Add_Constants=n ; ask for folder that contains the "*.ext.*" files $folder = FileSelectFolder('Select folder to process',"") ; using desktop as root folder if @error = 1 then exit ; create an array of the files in the selected folder that match the "*.ext.*" pattern $afiles = _FileListToArray($folder,'*.ext.*') switch @error case 1 msgbox(16,'*** ERROR ***','Folder not found or invalid') exit case 2 msgbox(16,'*** ERROR ***','Invalid Filter') exit case 3 msgbox(16,'*** ERROR ***','Invalid Flag') exit case 4 msgbox(16,'*** ERROR ***','No Files Found') exit endswitch ; create a string of base file names to populate the first listbox local $tStr = '', $tfile for $1 = 1 to $afiles[0] $tfile = StringRegExp($afiles[$1], "(.+)\.\w{1,5}$", 3)[0] if stringinstr($tStr, $tfile) = 0 then $tStr &= '|' & $tfile next ; setup the gui and populate the "base filename" listbox local $gui010 = guicreate('Custom File Lister') local $aSize = wingetclientsize($gui010) guictrlcreatelabel('Base Files',0,5,$aSize[0]/2-10,20,$SS_CENTER) guictrlcreatelabel('Duplicates',$aSize[0]/2+10,5,$aSize[0]/2-10,20,$SS_CENTER) local $lst010 = guictrlcreatelist('',0,20,$aSize[0]/2-10,$asize[1]-20,$ss_sunken) guictrlsetdata($lst010,$tstr) local $lst020 = guictrlcreatelist('',$aSize[0]/2+10,20,$aSize[0]/2-10,$asize[1]-20,$ss_sunken) local $dummy010 = guictrlcreatedummy() local $dummy020 = guictrlcreatedummy() guisetstate() ; register the command mssage processor GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") while 1 switch guigetmsg() case $gui_event_close Exit case $dummy010 ; actioned by _WM_COMMAND $tstr = '' for $1 = 1 to $afiles[0] if stringinstr($afiles[$1], _GUICtrlListBox_GetText($lst010,_GUICtrlListBox_GetCurSel($lst010))) > 0 then $tStr &= '|' & $afiles[$1] next guictrlsetdata($lst020,$tstr) case $dummy020 ; actioned by _WM_COMMAND msgbox(0,'Do Something with the File','File = ' & _GUICtrlListBox_GetText($lst020,_GUICtrlListBox_GetCurSel($lst020))) EndSwitch WEnd ; command processing routine ; monitors command messages for selection changes within either listbox and actions the appropriate control Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg switch $lParam case guictrlgethandle($lst010) switch BitShift($wParam, 16) case $LBN_SELCHANGE guictrlsendtodummy($dummy010) EndSwitch case guictrlgethandle($lst020) switch BitShift($wParam, 16) case $LBN_SELCHANGE guictrlsendtodummy($dummy020) EndSwitch endswitch EndFunc ;==>_WM_COMMAND kylomas Hi, you´ve done a heck of job there. It´s great for pointing me the way. Now give some time to study the code. Cheers. Jose Link to comment Share on other sites More sharing options...
iamtheky Posted September 3, 2014 Share Posted September 3, 2014 Hi. I like your idea, but sometimes I have: file.ext file.ext.10 file.ext.1000 etc... The program starts with file.ext and saves a new file every time I save, incrementing extension. Wait, there is just a plain .ext file in there? If you do a normal FileDialog with *.ext, those are the only files that will show. $selectedfile = fileopendialog("ext files" , @Scriptdir , "EXT(*.ext)") ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Belini Posted September 3, 2014 Share Posted September 3, 2014 (edited) I made an example, see if it helps #include <File.au3> #include <Array.au3> #include <String.au3> list_files() Func list_files() Local $list_file, $count_file, $Var1, $total_arq, $Var2, $filter, $found Local $directory = FileSelectFolder("Browse for Folder.", "") Local $make_list = _FileListToArray($directory, "*", 1) If Not @error Then $filter = StringSplit("au3|ini|txt", "|") $found = "" For $Var1 = 1 To $make_list[0] For $Var2 = 1 To $filter[0] If StringRight($make_list[$Var1], 4) = "." & $filter[$Var2] Then $found &= $make_list[$Var1] & "|" EndIf Next Next $list_file = _StringExplode($found, "|", 0) _ArraySort($list_file) _ArrayDisplay($list_file) EndIf EndFunc ;==>list_files Edited September 4, 2014 by Belini My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ 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