karthikeyan_coder Posted February 19, 2007 Share Posted February 19, 2007 Hello, I need to list a directory's all sub-folders and its files... i've tried for directory listing alone... $list_ignore = array ('.','..'); $main_trace_dir = "uploads"; $handle=opendir($main_trace_dir); while ($file = readdir($handle)) { if (is_dir($file) && !in_array($file,$list_ignore)) { echo $file; } } closedir($handle); lets say the directory structure is... uploads |______Subfolder A | |_________Subfolder 1 | | |__________Some file.zip | | |__________Some other file.mp | |_________Subfolder 2 | |_________file. |______Subfolder B | |_________X | |________ |some file in main directory.zip actually the number of files and subfolders of "uploads" is numerous... Current code is trying to list just "Subfolder A, Subfolder B" ... actually i have to extract *.zip files and move the contents to some directory like "extracted". if it is not zip then just move to "extracted"... i dont know how to execute subfolders/files section... any help? Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted February 20, 2007 Author Share Posted February 20, 2007 any idea? Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted February 20, 2007 Author Share Posted February 20, 2007 still i am waiting... any gurus can help me? Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 20, 2007 Share Posted February 20, 2007 Just to clarify, you want a code that will present the directories like you typed out or you want a code that will move files around based on whether or not they are extracted, or both? Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted February 20, 2007 Author Share Posted February 20, 2007 have to Extract if it is zip and move. else just move if current file is a zip then ______________________ example content of a zip somefile.zip --------------> titleimage.jpg -------------->song.mp3 -------------->song2.mp3 someother.zip ------------->song3.mp3 -------------->song4.mp3 if the current file is a zip then we have to extract and move the files. if the extracted file is an image then ... /uploads/images else /uploads/songs if the current file is a *.mp3 then ____________________________ just move to /uploads/songs i've tested that.. unzip command is working... i dont know how to move after extraction... Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 20, 2007 Share Posted February 20, 2007 I believe the rename() function will move the file. http://us3.php.net/rename Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted February 20, 2007 Author Share Posted February 20, 2007 ok. but my primary problem is tracing through subfolders... Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 20, 2007 Share Posted February 20, 2007 1.download a free shell for windows or linux. 2.make three folders or as meny needed 4.use the command exec to execute the new shell program to unzip all ziped files into a temp folder. 5. use a for loop to go throw the files to detect exstention's. 6. within the for loop use move_uploaded_file to the destination of the file enstention. there you go. Quote Link to comment Share on other sites More sharing options...
JBS103 Posted February 20, 2007 Share Posted February 20, 2007 I was thinking something like this. This will only work if you have PHP 5 though. Scandir isn't supported for 4. <?php //Array of content $files = scandir($dir); //Get rid of . and .. $files = array_slice($files, 2); //Loop for the number of files/contents for($x = 0; $x < count($files); $x++) { //This should be a little bit more advanced to get rid of other extensions so you are left with only directories, but you get the point if(preg_match("/.mp3/", $files[$x])) { //Move rename("/oldpath/oldpath/oldpath/".$files[$x], "/newpath/newpath/newpath/".$files[$x]); //Take them out of the array unset($files[$x]); } } ?> Now the $files array only has directories left (technically, you will need to do more searching to weed out the rest). I would probably consider making what I did above into a function so you can continually loop to go through all the directories. I am unsure as to how decent my code is. In fact I would assume its poor. I know it works, but the goal was just to get you some ideas. Sorry if it is useless. Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted February 20, 2007 Author Share Posted February 20, 2007 thanks for your replies... i am just gonna work on it. any more ideas? Quote Link to comment 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.