Sign in to follow this  
Followers 0
creativemind7

Searching in Text File.

5 posts in this topic

Dear Sir!

I'm making a script which stores all paths of my files (including file names) to a Notepad file in seperate lines and also show file size.

I coded the script, and it successfully stores my required information i.e (FilePath+FileName+File Size), but now i want to search in this text file (FileList.txt) for a specific string (i.e file size) and if the specific string is existed in my text file, then Autoit should give me the following results :-

1) Copy only that lines to another Text File which have my required/specific string for which i am searching. (but remember only File Paths + File Names and not File size)

Here is the example of Text File (FileList.txt).

D:\My Documents\Coral Files\25 Hadiss.cdr 115254 bytes

D:\My Documents\Coral Files\golden.cdr 36382 bytes

D:\My Documents\Coral Files\Asif Card V9.cdr 13979070 bytes

D:\My Documents\Coral Files\ASIF SHAHJEE CLERK.psd 11790593 bytes

D:\My Documents\Coral Files\awan club.cdr 36382 bytes

D:\My Documents\Coral Files\Bannu sugar mills card.cdr 15007036 bytes

You can see that every file has its path plus its size. i want to search for the string "36382". You can see that 36382 is in Line No. 2 and in Line No.5. i.e :

D:\My Documents\Coral Files\golden.cdr 36382 bytes

D:\My Documents\Coral Files\awan club.cdr 36382 bytes

Now i want to copy these file's paths to another Text file (SearchList.txt) but only file path and its file name and not the file size. In other words i want to copy only red color text excluding blue color text to another text file (which could be named "SearchList.txt".

that's all....

I will be waiting for reply..........I may be also be informed by my following email address when some one expert gives reply.

Thanks and forgive me for my English because English is not my mother language.

Well Wisher: creativemind7@yahoo.com

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

creativemind7,

Welcome to the AutoIt forum. :D

I would use _FileReadToArray to get the contents of your file into an array. You can then loop through the array and use StringInStr to see if the numerical value you require exists in a particular element. If it does, you can use the return value of StringInStr as the "count" parameter in StringMid to extract the path of the file. Finally you can use FileWriteLine to add this path to the new file you are creating. :rip:

Pretty easy stuff - give it a go yourself. You know where we are if you need help. :oops:

M23

Edit: Amended function to use - thanks Zedna. :)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Zedna,

Thanks for picking that up. :D

I have a dreadful cold at the moment and I am really not feeling myself. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Melba and Zenda, Thanks for helping....

My code is working now in the light of your advice.......

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  
Followers 0