i used the stat() function to return information about some files but unfortunatly when i tried to open those files i found them empty. can you help me to get back the contents of those files because they are imprtant to me. some of them were contain assignments. and i also want to know why their contents were deleted? and how to avoid this in future?
note: the files still exist but with size 0
hana , Thank you for your question.
It is impossible to say why your files were truncated to zero length. One possibility (of many) is that you may have opened them for writing then closed them without writing them.
There are many products for undeleting files, but these all assume that the files were deleted by using file deletion commands or functions. If your files truly were truncated to zero length, there is no reliable way to recover their contents.
One possibility for recovery: You can write (or perhaps find) a program to scan the entire hard drive, reading the disk surface using low-level commands, looking for strings contained in the deleted files. Such a scan might take an hour or two to complete, depending on the size of your hard drive. This method might recover some of your data if your operating system saved the files in different sectors at various points in time. There is no guarantee that this is the case.
I tried the program with another file and i used the extension $$$ then the contents of the file were not deleted but the size of the file was displayed as 0, how can i get the actual size? and do i have to use the extension $$$ with any file?
Unfortunately, you did not state your Operating System, which might be some flavor of Linux, Sun OS, Windows 3.x, Windows 9x/ME, Windows NT/2000, Windows XP, Windows Longhorn, MSDOS, MacOS, etc.
The 'stat' function reads Unix-specific information about a file from a file system directory. It does not read or write the file itself, so it cannot change the length of the file.
An extension of '$$$' has no special meaning; however, a particular operating system might use this extension internally to mark a file as deleted or for any other purpose. I do not recommend using this extension yourself.
You can get the actual size of a file by opening it (using the 'open' or '_open' function), seeking to its end (using the 'seek', 'lseek', or '_lseek' function), then finding its current buffer position (using the 'tell' or '_tell' function).