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. 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. 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. 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 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 . 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
Archived
This topic is now archived and is closed to further replies.