At a specific folder in the system there is a file.
I know that its name is a number, and I have that number in a variable.
What i don’t know is what extension this file has.
How do i scoop up this file?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EDIT: As Ikegami notes below, this is sensitive to the particular pathname of the directory. It will fail if that directory name contains spaces or other special characters. You can mitigate that by wrapping the non-wildcard portion of the string in embedded quotation marks:
But that will still fail for e.g.
$specific_folder_in_the_system = "/Users/O'Neal, Patrick";.If you don’t mind changing your current working directory, you can
chdir($specific_folder_in_the_system) or diefirst and then use justglob("$that_number.*"), which should be safe as long as$that_numberis really a number.You could also use a combination of
opendirandgrepin lieu ofglob: