Jump to content
ravaged1

Check for part of a file name with wild cards

Recommended Posts

ravaged1

Looking for ideas

I have 2 files.

xxxxxD.txt and xxxxxP.txt  I need to restore them to right place, but to do that I need to know if it's *D.txt or *P.txt.

They will overwrite the corresponding files. attempted to try with this but I didn't expect it would work. Any help would be appreciated.

$Restore_FileName = _PathSplit($Restore_FilePath, $R_szDrive, $R_szDir, $R_szFName, $R_szExt)
                $NameMatch = $R_szFName & $R_szExt
                If $NameMatch = "*D.txt" Then
                    MsgBox(4096, "Found D", $NameMatch)
                Else
                    MsgBox(4096, "?", $NameMatch)
                EndIf

 

Edited by ravaged1

Share this post


Link to post
Share on other sites
Melba23

ravaged1,

Just the job for a RegEx:

#include <File.au3>

Local $R_szDrive, $R_szDir, $R_szFName, $R_szExt



$Restore_FilePath = "C:\Foo\xxxxxD.txt"
$Restore_FileName = _PathSplit($Restore_FilePath, $R_szDrive, $R_szDir, $R_szFName, $R_szExt)
$NameMatch = $R_szFName & $R_szExt

If StringRegExp($NameMatch, "^.*D\.txt$") Then
    MsgBox(4096, "Found D", $NameMatch)
Else
    MsgBox(4096, "?", $NameMatch)
EndIf



$Restore_FilePath = "C:\Foo\xxxxxP.txt"
$Restore_FileName = _PathSplit($Restore_FilePath, $R_szDrive, $R_szDir, $R_szFName, $R_szExt)
$NameMatch = $R_szFName & $R_szExt

If StringRegExp($NameMatch, "^.*P\.txt$") Then
    MsgBox(4096, "Found P", $NameMatch)
Else
    MsgBox(4096, "?", $NameMatch)
EndIf

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
ravaged1

ravaged1,

Just the job for a RegEx:

#include <File.au3>

Local $R_szDrive, $R_szDir, $R_szFName, $R_szExt



$Restore_FilePath = "C:\Foo\xxxxxD.txt"
$Restore_FileName = _PathSplit($Restore_FilePath, $R_szDrive, $R_szDir, $R_szFName, $R_szExt)
$NameMatch = $R_szFName & $R_szExt

If StringRegExp($NameMatch, "^.*D\.txt$") Then
    MsgBox(4096, "Found D", $NameMatch)
Else
    MsgBox(4096, "?", $NameMatch)
EndIf



$Restore_FilePath = "C:\Foo\xxxxxP.txt"
$Restore_FileName = _PathSplit($Restore_FilePath, $R_szDrive, $R_szDir, $R_szFName, $R_szExt)
$NameMatch = $R_szFName & $R_szExt

If StringRegExp($NameMatch, "^.*P\.txt$") Then
    MsgBox(4096, "Found P", $NameMatch)
Else
    MsgBox(4096, "?", $NameMatch)
EndIf

M23

​The Script above won't fail. If I remove a file or the D and P but I see where StringRegExp is the way to go. Thanks a lot I'll dig into it.

Share this post


Link to post
Share on other sites
Melba23

ravaged1,

The Script above won't fail. If I remove a file or the D and P

I am afraid I do not understand your comment. The script does exactly what you asked:

I need to know if it's *D.txt or *P.txt

So what is it that you really want to do?

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
ravaged1

ravaged1,

I am afraid I do not understand your comment. The script does exactly what you asked:

So what is it that you really want to do?

M23 

​I just meant I gives the Found message even if the files doesn't exist.

You did answer my question though, I just needed to find a function that would help me determine if a file ends with P then do stuff If D then do other stuff.

Share this post


Link to post
Share on other sites
Melba23

ravaged1,

Fine - as long as you have what you need.

Although in future when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

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
ravaged1

I don't like all the extra text either, 1st time with the new forum.

It's nice, clean and modern though just not idiot proof. :>

Share this post


Link to post
Share on other sites
Melba23

ravaged1,

It's nice, clean and modern

Most people seem to think that it is too washed-out - nice to hear a positive comment for a change.

just not idiot proof

Given the number of bugs we are finding, it is not just idiots who need proofing against!

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

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

×