david1337

FileRead Case sensitive

13 posts in this topic

Hi guys

I hope you can help me out :)

I have a script that checks for the current user's loginname in different txt files.
If the current user's loginname is found in one of the txt files, the script reacts based on that.

The text files look something like this:

dle
oej
zaq
oei

 

(different usernames)

 

This is an example of the script:

$username = @UserName    ;pulls username that is logged in

$Dir = "C:\Test\"

Global $Custom[] = ["text01", "text02", "text03", "text04"]


;CHECK LISTS
For $i = 0 To UBound($Custom) - 1

$CustomFile = FileOpen($Dir & $Custom[$i] & ".txt", 0)
$Readtxt = FileRead($CustomFile)
FileClose($CustomFile)

If StringRegExp($Readtxt, $username) Then

do this and that...

EndIf
Next

It works perfectly if the user logs in as xxxx or XXXX (Both lower and upper case characters)
So the FileRead function doesn't seem to be case sensitive.
But if the user logs in as xxXx (mix of lower and upper case characters), then the username is not recognized in the txt file.

 

Does anyone have a suggestion on how I can fix this?

Thanks in advance!

- David
 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

david1337,

Use StringUpper/Lower on both the file content and the user name - or use the case insensitive flag "(?i)" in your RegEx  pattern.

M23

Edited by Melba23
Improved visiblity of RegEx flag
1 person likes this

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

#3 ·  Posted (edited)

If StringRegExp(StringLower($Readtxt), StringLower($username)) Then

 

Edit: Melba23 had the better answer.
 

Edited by Exit
1 person likes this

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Hi guys

Thanks for your answer!

Exit's soloution --> "If StringRegExp(StringLower($Readtxt), StringLower($username))"  seems to have done the trick, which confuses me :)?

Melba you tell me in your post that I should also include a StringUpper - why does it work without that?

- David

Share this post


Link to post
Share on other sites

david1337,

You can use either StringUpper or StringLower - just as long as you use the same one on both elements. But making the RegEx case-insensitive as I suggested would be much the better solution.

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

#6 ·  Posted (edited)

Melba23,

Ahh okay I get it :) That's why it works.

 

Anyway, I will try to figure out to how to make the RegEx case-insensitive instead then, when Melba himself recommends it!

As always, thank you for taking your time to explain things!

- David

Edited by david1337

Share this post


Link to post
Share on other sites

david1337,

I will try to figure out to how to make the RegEx case-insensitive

I showed you above - add (?i) at the start of the pattern.

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

Hint...$readtxt is your patern.  Concatenate the case modifier in front of it...


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

Share this post


Link to post
Share on other sites

kylomas,

The pattern is "$username".

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

wider....wider....wider....OK, swallow foot!!!


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

Share this post


Link to post
Share on other sites

kylomas,

It is known here as "dontopedology" and we are all liable to suffer from it at times.

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

M23,

My new favorite term (and watch word), thanks!

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

Share this post


Link to post
Share on other sites

we are all liable to suffer from it at times.

I can testify !! ( times where unfortunately I'm also like this)

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

  • Similar Content

    • wimhek
      By wimhek
      Is it possible , and how can I read and write txt files from Icloud (apple service) ?
      Let me try to explain my application.
      On my Ipad and Iphone I create txt files. On my windows computer it is possible to read and modify these files manually, by logging in on www.icloud.com.
      What I want to make is an auto-it script who reads the txt file and create an new txt file on www.icloud.com,  so I can acces these on my ipad and/or phone.
       
      Thank you.
    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
      Autorun.inf
    • antmar904
      By antmar904
      Hi,
      I ran a remote program on 180 computers and logged the output to a log file with paexec.  I'm trying to parse through the log file to see which computers launched the program successfully and record the computer name but I'm not sure how to go about it. 
      I can successfully open the log file, read it but not sure how to start separating the data.
      I've attached the log file, basically every computer entry in the log file for a new computer starts with "Connecting to <computername>..." I was thinking about using that as the start and stop point for retrieving the end results.  Anything with a "returned 0" is a success, everything is a fail.
      Any help is much appreciated.
      testlogfile.txt
    • souldjer777
      By souldjer777
      Howdy Everyone!
      I've been scouring the forum for something that works... and no dice yet... hoping to stop the frustration - hope someone in the forum knows what to do.
      Basically, I've saved .msg files out of MS Outlook and want to scan each on for email addresses but all I get with fileopen and fileread are symbols... ran through every iteration.
      I've seen people do some soft of binary extract and binarytostring but I haven't gotten that to work either... not sure what's going on.
      Neither of these have worked for me... yes I know they are old and FileOpen has changed... but like I said I tried everything that I know of.
      Please help
       
      $sFile = "C:\temp\messages\Test.msg" $hFile = FileOpen($sFile, 16) ; 16 = binary $binData = FileRead($hFile, 1024) ; read first 1KB FileClose($hFile) ConsoleWrite("Debug: First 1KB = " & $binData & @LF) or...
      $sFile = "C:\temp\messages\Test.msg" $hFile = FileOpen($sFile, 16) $binData = FileRead($hFile, 20480) FileClose($hFile) $startdef=StringTrimLeft(Binary('thetextIamlookingfor'), 20) $enddef=StringTrimLeft(Binary('moretextIamlookingfor'), 20) $binData=StringTrimLeft($binData, StringInStr($binData, $startdef)+StringLen($startdef)-1) $binData=StringLeft($binData, StringInStr($binData, $enddef)-1) ConsoleWrite(BinaryToString('0x'&$binData) & @LF) Thanks!
    • souldjer777
      By souldjer777
      Good Morning All,
      I'm hoping someone here can work their AutoIT magic 
      I'm doing a pretty "simple" string search in a HUGE variable.
      But I'm doing the basics almost straight out of the Help File...

      ( sorry, I'm leaving out my main code for privacy reasons )
      Local $hFileOpen = FileOpen($sFilePath, $FO_READ) Local $sFileRead = FileRead($hFileOpen) Local $sEmailPosition01 = StringInStr ($sFileRead, $sEmailAddress ) Everything looks good with my troubleshooting
      I ran IsString against $sFileRead and $sEmailAddress and was okay: "The variable is a string"
      So then I ran StringLen($sFileRead) and got string length 68352786
      Yeah, I know... That's HUGE - But it worked with the older version of AutoIT (upgraded yesterday) v3.3.14.2
      Is there an "Excessive" variable I should set?!? lol. Should I search the string a different way maybe?
      I know the string is in there... but I'm getting a StringInStr @error : 0 @extended: 0
      Please help! Thank you all