Browse directory file

2

I have a directory on the network with thousands of TXT files generated by other software contracted in the company. The file is named with the following logic:

 (cpf do cliente)(data da insercao)(hora insercao).txt
 1234567894120150501142024.txt

I need to select the txt that corresponds to the client's cpf, but I can not find the file.

Please help me

    
asked by anonymous 25.05.2015 / 19:05

2 answers

3

Use the glob () function to do this.

foreach (glob("00000000000*") as $file) {
    $user = $file;
}

Note that in the definition of the default there is a * that is used to define that everything that comes after $cpf is irrelevant to the search, so you will receive as a return all the files that have at the beginning a value that is equal to the CPF equal to the one sought.

    
25.05.2015 / 19:42
1

I have not tested, but I believe glob () will solve the problem. If you know the CPF, you can do something like

$cpf = "12345678900*";
    foreach (glob($cpf) as $arq) {
    echo "$arq" ."\n";
}

It returns the name of the file that has the cpf you passed.

    
25.05.2015 / 19:16