Strahd Posted December 1, 2012 Share Posted December 1, 2012 Hello all, I have this code which currently reads 1 .txt file in a folder. How can I modify it so that it gets information from *.txt files in the folder? $data_file = @$argv[1]; if (empty($data_file)) { die("\nUsage: {$argv[0]} path/to/data/file.txt\n\n"); } $db = getDb(); // $fd = fopen($data_file, 'r'); I appreciate any help anyone is willing to offer. Quote Link to comment https://forums.phpfreaks.com/topic/271433-getting-information-from-all-txt-files-in-a-folder/ Share on other sites More sharing options...
trq Posted December 1, 2012 Share Posted December 1, 2012 glob. Quote Link to comment https://forums.phpfreaks.com/topic/271433-getting-information-from-all-txt-files-in-a-folder/#findComment-1396606 Share on other sites More sharing options...
Strahd Posted December 1, 2012 Author Share Posted December 1, 2012 glob. As a substitute for fopen or argv? I apologize for the ignorance, I am very new at this. Quote Link to comment https://forums.phpfreaks.com/topic/271433-getting-information-from-all-txt-files-in-a-folder/#findComment-1396607 Share on other sites More sharing options...
DavidAM Posted December 1, 2012 Share Posted December 1, 2012 In his post, glob is a link to the manual where you can read what it does. It will return an array of filenames (you can use wildcards), so then you process each element of the array instead of reading the filename from the command line arguments. You will also need foreach Quote Link to comment https://forums.phpfreaks.com/topic/271433-getting-information-from-all-txt-files-in-a-folder/#findComment-1396683 Share on other sites More sharing options...
Strahd Posted December 1, 2012 Author Share Posted December 1, 2012 Thank you guys. The glob() and foreach() worked as advertised . Quote Link to comment https://forums.phpfreaks.com/topic/271433-getting-information-from-all-txt-files-in-a-folder/#findComment-1396754 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.