Archive: Search for File + Wildcard


Search for File + Wildcard
How do you find a file by use of a wildcard. I need to edit java settings in C:\Docs+Set\user\.java\properties131_**, where the ** can be anything from 01 - 25.

I know to use ReadEnvStr to get the users folder, but I need to open that properties file, no matter what the trailing numbers are.

Thanks in advance.

NSIS rules.

Coop


Has some functions in Archive that do exactly that.


I searched and searched and couldn't find any. There were plenty of functions that found the directory if you had the file name, but not the file name if you know the directory.


There were plenty of functions that found the directory if you had the file name, but not the file name if you know the directory.
You can use the "Search for a File" or "Search for File or Directory (Alternative)" functions to search for directories too. Like I have in my program (using "Search for File or Directory (Alternative)"):
Function YourFunction

Push "properties131_??"
Push "C:\Docs+Set\user\.java"
Push $0
GetFunctionAddress $0 "Search"
Exch $0
Push 0
Push 0
Call SearchFile

FunctionEnd

Function Search

# Your code for each folder, or for only one folder.

Push "go" ;or Push "stop" if you don't want to search anymore.

FunctionEnd

Maybe I am just not reading them right, but I looked at both of the functions you referenced and both wanted a "certain file". I don't know the file name, I know part of the file name, I want to find the rest of it.

Secondly, I dont understand the function you posted. Say I wanted to simply delete the file, where would that one line of code go?

Thanks deguix, I appreciate the help.


Oh, you wanted to delete the file...... But that's even easier! Just use:


Delete "C:\Docs+Set\user\.java\properties131_*.*"
I thought you wanted to search a file or folder because of the quote:
How do you find a file by use of a wildcard.

Sorry, I was just trying to use that as an example so I could see where to insert my code. I want to open the file, and replace a string (I've already got code to do that). I just wanted to see where in your example to do that.


Just use FindFirst, FindNext etc

E.g.

FindFirst $R0 $R1 "X:\path\to\files*.*"
Loop:
Push $R0 ;store file handle
Push "X:\path\to\$R1" ;current found file
Push ...
Call Func
Pop $R0
ClearErrors
FindNext $R0 $R1
IfErrors 0 Loop
FileClose $R0


-Stu