.dat files.... finding out if they're empty

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby swirlee » Sat Jul 05, 2003 1:40 pm

I'm not entirely sure what you're looking for. If you want to know if a file is empty (e.g. 0 bytes), simply test with filesize('filename.txt'). If it returns 0, the file is empty. As for '.dat' files -- .dat is an extension that's been used, perhaps, by more programs than any other. My only guess is that perhaps you're referring to the .dat files that contain incomplete downloads in FastTrack network P2P apps like Kazaa and Morpheus, and in this case, I can understand your quandry -- if you start a new download in Kazaa, it creates a file with a name like download00000000000000000000000.dat, and even if it hasn't downloaded a single byte of data, that file isn't zero-length. If I remember correctly, it's about 102kbytes. Well, one way to do this, I suppose, is just test if it's greater than 102kB (or whatever the number is -- I may have it wrong, so do some investigating). The "right" way to do it, though, would probably be to find some documentation about the .dat file format (a cursory Googling found this), then use PHP's fread() and related functions to figure out if the file contains any downloaded data, or just header info, etc. But to do this, you're going to have to get your hands pretty dirty. Good luck.

User avatar
Posts: 312
Joined: Sat Apr 05, 2003 4:33 am
Location: Mansfield, UK

Postby bezmond » Sun Jul 06, 2003 1:33 am

the 128kbyte thing is because it stores things like the final filename, the user(s) it's downloading from and details like that.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 7 guests