Operating Systems :: Unix :: delete 0byte files |
|||
| By: roe1and |
Date: 07/11/2007 16:02:03 |
Points: 20 | Status: Answered Quality : Excellent |
| is there an easy way of removing 0 byte files from a directory without harming the other files. and if yes, is there a way of removing the files that are less than a certain size. say less than 10KB? | |||
| By: VGR | Date: 07/11/2007 18:34:40 | Type : Comment |
|
| yes. Very easy. Using PHP or a windows executable (or service) ? everything is possible... basically, it's the algorithm : - get directory files in a loop^(eventually matching a given mask) - examine filesize - if less than threshold, delete file - loop very very very easy including in PHP |
|||
| By: roe1and | Date: 07/11/2007 20:42:00 | Type : Comment |
|
| Easy big guy... I know even less of Unix than I do of PHP. Could you do a step-by-step using PHP please? | |||
| By: VGR | Date: 08/11/2007 00:10:14 | Type : Answer |
|
| ok <?php $dirhandle=@opendir("."); while (FALSE !==($dir = @readdir($dirhandle))) { echo "entry read = $dir ".(is_dir($dir)?'directory':'file').' '; } // while ?> add a filesize() call and a test for the threshold in the middle, add an unlink() call and you're done. ok ? |
|||
| By: roe1and | Date: 08/11/2007 11:23:55 | Type : Comment |
|
| that makes sense thanks. i think my current problem is that i'm trying to access a directory on the works network using a php script that is located on a server in south africa(i'm from there) i've been trying just opening c:/windows or c:\windows or anything for that matter. but i'm struggling. please help. i should have studied something useful like programming instead of graphic design. if only i'd known... | |||
| By: VGR | Date: 08/11/2007 19:43:46 | Type : Comment |
|
| which C: drive ? yours ? or the server's ? | |||
| By: roe1and | Date: 08/11/2007 20:42:13 | Type : Comment |
|
| not the servers. although the information i need to check is on the server | |||
| By: VGR | Date: 08/11/2007 23:19:09 | Type : Comment |
|
| using PHP, you run on the server, so your client's (browser's) C: drive will be completely inaccesisble. javascript, or a java applet, or a silly ActiveX (COM+ object) runs on the client and thus will be better placed to access your C: drive ;-) (even if for security reasons they may not be able to R/W on your drives) |
|||
| By: roe1and | Date: 09/11/2007 10:28:38 | Type : Comment |
|
| no worries i've abandoned this idea altogether. there is just too much information to work through so it will just take forever. this means i have turned to perl. it took me the whole of yesterday to write a script that reads all the files in a directory into an array and then prints it back out. wish me luck! is there anywhere that you know of where i can get some support for perl? thanks again for all your help |
|||
| By: VGR | Date: 09/11/2007 21:39:46 | Type : Comment |
|
| excuse me ? Perl is less powerful and less useful than PHP Perl can only access the server's directories, whilst you wrote "not the server's". PHP can do this better and not in "the whole of yesterday" ;-) (I already gave youthe algorithm above ; it already prints out entries like "dir" output) |
|||
| By: roe1and | Date: 10/11/2007 11:07:52 | Type : Comment |
|
| i wouldn't want to get into the whole php is better than perl thing. there's enough of that going around. personally i quite enjoy php, i find it's quite forgiving if you dont know what you're doing like me. unfortunately i work at a place where i'm the only person that works with php. everybody else either uses perl or python(?!?) at the moment i'm trying to get them to install php on one of the servers(that will make my life a lot easier, at the moment i'm using a server that belongs to a hosting company in south africa). i don't see how i can get around using perl for at least some of the work related suff i do. and at least i have people at hand that i can as for advice too.(fyi. i already know for a fact that they are not as knowledgeable as you are(what are you - a borg from star trek?)). plus if i become more proficient in perl it can only benefit my php(right?). don't worry i already have a few more php questions lined up and i really, really feel that i have come to grips with programming and php a lot since joining this forum. thanks for your dedication and hard work! ... what's an algorithm? | |||
| By: VGR | Date: 10/11/2007 15:50:29 | Type : Comment |
|
| I don't say PHP is better than Perl, althought I think it is. I say they are similar and none of the two can render more services than the other. Like Pascal and C for instance. In your case of accessing client's hard drive from the server, nor Perl nor PHP can do it. that's what I was writing. I also know some Perl, and in fact I think that if you know ONE programming laguage of the class dubbed "L3G", then you may use any other language of that class. The best being if you know Ada, of course. BTW PHP can run Perl programs, whereas Perl can not run PHP programs ;-)) it's ONE of the reasons I prefer PHP. I also prefer PHP for readability, AND for performance despite some Perl specialists could say otherwise, be them right or not. I did performance measurements. I also ran into walls using Perl, ported the code to PHP, and voila. It works. That's life. You've to learn to quickly detect the most suitable tool for completing your tasks, don't you agree ? ;-) And given I'm very lazy, as are all programmers, I prefer tools that save my time in stead of those that are sexier, more hype, favoured, recognized, promoted (think : Microsoft ASP.Net ;-)) as for your last question, an algorithm is the sequence of operations/instructions that you've to follow to complete the task. A program is that algorithm once translated in machine code [whatever the level of that code, from binary to Ada], and a process is the program whilst it runs on the target platform. as once wrote my Programming God : "Algorithms + Data Structures = Programs" (this is a book at Prentice-Hall, perhaps you should read it ;-)) HTH |
|||
| By: spoonman | Date: 04/01/2008 13:25:28 | Type : Comment |
|
| If you only have samba access to the directory in question, this question should be posted under Windows or DOS. However, This was posted under the "unix questions" so to satisfy people coming here to find the unix way of doing it, this is the standard unix way. to see 0 bytes files: find -size 0c -print To remove 0 byte files: find -size 0c -exec rm -f {} \; Naturally you change the argument following size to set size limitations. For example: < 20 bytes find -size -20c -print < 50 kilobytes find -size -20k -print > 50 bytes find -size +20k -print = 20 kilobytes find -size 10k -print You could also use this technique in the scheduling program 'chron' to do these deletions at regular intervals. Hope that helps |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








