clanstyles Posted June 27, 2007 Share Posted June 27, 2007 Hey, im trying to isolate the file size from the file/folder names. I have come up with this but it doesn't work right and well. exec("du -s *", $output); for($i=0; $i < sizeof($output); $i++) { echo $output[$i]; if($output[$i] == "\t") { echo "====>" . $output[$s] . "<br />"; } //echo $output[$i] . "<br />"; } Could somebody please help. Thank You in advance. Quote Link to comment Share on other sites More sharing options...
Lumio Posted June 27, 2007 Share Posted June 27, 2007 I found a self-made function on php.net: medhefgo at googlemail dot com 02-Jun-2007 03:02 I created another dirsize() function which doesn't use recursion. I gained a ~2-3% performance boost while it uses ~50% lesser memory! <?php function dirsize($dirname) { if (!is_dir($dirname) || !is_readable($dirname)) { return false; } $dirname_stack[] = $dirname; $size = 0; do { $dirname = array_shift($dirname_stack); $handle = opendir($dirname); while (false !== ($file = readdir($handle))) { if ($file != '.' && $file != '..' && is_readable($dirname . DIRECTORY_SEPARATOR . $file)) { if (is_dir($dirname . DIRECTORY_SEPARATOR . $file)) { $dirname_stack[] = $dirname . DIRECTORY_SEPARATOR . $file; } $size += filesize($dirname . DIRECTORY_SEPARATOR . $file); } } closedir($handle); } while (count($dirname_stack) > 0); return $size; } ?> Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 27, 2007 Author Share Posted June 27, 2007 Thats not what I need. I can get the fiel size fine with exec. I need to do it this way because im connecting with ssh2_connect to many servers I have this done already works fine. I get a print out with that exec like: 112 BMMods.rar8 Brent.txt12 BrentAIM.txt4 Gungame.rar4 Jumba.rar4 ReadMe.txt12 blackmarket12 carmod.rar4 config.php4 footer.php116 gungame.sql60460 half-life 2 deathmatch.rar4 header.php8 hl.class.php4 index.php284 java1300 layout.bmp49560 music652 raiderboy4 search.php4 ssh.php28 technicolor52 test4 whatismyip4 work.txt I need to get the filesize and the directory name seperate so I can hold them for each instance of that. So tahts why i was going to look for a space. I don't know the best way to do this though/ Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 27, 2007 Author Share Posted June 27, 2007 Bump** Sorry for this I am sitting here waiting lol Its fine just Like to l et you guys know:D Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 Anyone?? Quote Link to comment Share on other sites More sharing options...
corbin Posted June 28, 2007 Share Posted June 28, 2007 What does it say if you echo $output? I'm not very Linux knowledgable, but if you tell me that, I can probably help you format it correctly to extract the file size ;p. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 What im trying to do is basicly break up each line of output into Size and Name. It includes folders. So if the output is 120k Foldername123mFoldername I need it in byes btw, $size = 120 $foldername = foldername And repeate for each line of ouptput.. Quote Link to comment Share on other sites More sharing options...
clanstyles Posted June 28, 2007 Author Share Posted June 28, 2007 Do you get it kinda? 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.