physaux Posted November 2, 2009 Share Posted November 2, 2009 Hey guys, I got a big project ahead of me, I was hoping someone could point me in the right direction. So I have a text file, that I downloaded. It is formatted like so: ID [TAB] NAME [TAB] RANK1 [TAB] RANK2... ID [TAB] NAME [TAB] RANK1 [TAB] RANK2... ID [TAB] NAME [TAB] RANK1 [TAB] RANK2... ID [TAB] NAME [TAB] RANK1 [TAB] RANK2... ID [TAB] NAME [TAB] RANK1 [TAB] RANK2... ...//and so on What I want to do is essentially "batch process" this text file, to create the following folder structure: The main folder would have different folders inside of it, one for each "RANK1". In of these folders, there would be another folder for "RANK2" ex: ID [TAB] NAME [TAB] dog [TAB] charlie... ID [TAB] NAME [TAB] dog [TAB] woof... ID [TAB] NAME [TAB] cat [TAB] meow... would create: [dog], [cat] inside of [dog], there would be two folders; [charlie],[woof] inside of [cat], there would be one folder; [meow] Get it? Ok, Now the last part. Inside of each final folder, I want to place a text file with some text. Ex: in [dog][charlie] I would place index.php, contents = "THIS IS CHARLIE THE DOG" MY IDEAS: I would read the text file line by line, then "explode" each line by the "tab" into an array, which I would then analyze. How would i go from there? Thanks! Could anyone point me in the right direction? Ty Link to comment https://forums.phpfreaks.com/topic/179981-solved-text-processing-making-folders-based-on-data-whaaattt/ Share on other sites More sharing options...
cags Posted November 2, 2009 Share Posted November 2, 2009 Once you have a row loaded, you can simply use file_exists to check if $arr[2] exists, if it doesn't then create it using mkdir, then check if $arr[2] . "/" . $arr[3] exists and do the same, stop rinse repeat for each level you have. Link to comment https://forums.phpfreaks.com/topic/179981-solved-text-processing-making-folders-based-on-data-whaaattt/#findComment-949465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.