Jump to content
Sign in to follow this  
johnmcloud

Include/Exlude word(s) from a txt/array

Recommended Posts

johnmcloud

Hi guys,

I'm usign by a bit of time, very useful, I can include/exclude file extensions/folder or select subfolder, and many other. I have this situation now:

I want to select example .txt files but i want to exlude the word(s) "time" and "sea" from the filename

Example of the basic array:

C:TestMoon.txt
C:TestEarth.txt
C:TestEarth_is_my_time.txt
C:TestSea_on_the_moon.txt

Result without the word(s) "time" and "sea" will be:

C:TestMoon.txt
C:TestEarth.txt

In the same way, example i will only include the word(s) "time" and "sea", the result will be:

C:TestEarth_is_my_time.txt
C:TestSea_on_the_moon.txt

I don't know if this can be do directy on the array, anyway i can save the array on a .txt and then include/remove the word(s). I'll create a GUI for this, but i don't have problem with the gui creation.

Some advice?

Thanks ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites
someone

You can definitely accomplish what you are trying to do, this is how I would do it, (code is written on the fly but you will get the idea)

For $i = UBound($array) - 1 to 1 Step -1

If StringInStr($array[$i], "time") Then

_ArrayDelete($array, $i)

EndIf

If StringInStr($array[$i], "sea") Then

_ArrayDelete($array, $i)

EndIf

Next

_ArrayDisplay($array)

Code could be optimized but you will get the idea. Step through the array BACKWARDS, so when you delete an element you don't have to worry about adjusting the amount of times the loop runs (change it to going forwards and you'll see what I mean).


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

The UDF will do it directly - just use the various parameters to define the files you want to include/exclude. :)

This script works as you require when I use your posted filenames: ;)

#include <array.au3>
#include <recfilelisttoarray.au3>

; Exclude "time" and "sea"
$aArray = _RecFileListToArray("Your_Path", "*.txt", 1, 0, 0, 1, "*time*.txt;*sea*.txt")

_ArrayDisplay($aArray)

; Only show "time" and "sea"
$aArray = _RecFileListToArray("Your_Path", "*time*.txt;*sea*.txt", 1)

_ArrayDisplay($aArray)

M23

Edited by Melba23
Wrong button too soon!

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
johnmcloud

Thanks Melba, i'll check it out ;)

Share this post


Link to post
Share on other sites
johnmcloud

Melba i have problem with "Include only..."

For "Exclude" i have make this:

$List = _RecFileListToArray($Folder, $FileType, 1, $SubFolder, 0, 2, GUICtrlRead($Input), "")

And work.

For "include only" this not work:

$List = _RecFileListToArray($Folder, GUICtrlRead($Input), 1, $SubFolder, 0, 2, "", "")

Give me error for the array. Where i need to add the $SubFolder variable and have the full path? I have the same parameter of "Exclude", i don't know where i'm doing wrong.

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites
Melba23

johnmcloud,

How about some explanation of the folder structure you are trying to parse and the sort of things you expect to find in the $Input control? And you are using a variable $SubFolder where I would expect to see an integer defining the type of recursion you want the UDF to use - what is this variable? ;)

I am very willing to help, but I need some information to work on! :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×