As you’ll probably agree, a decent directory iterator class wouldn’t be complete if it’s not capable of dealing with timestamps. Fortunately, the “DirectoryIterator” class won’t disappoint you (at least regarding this specific aspect), since it’s been provided with some interesting methods that retrieve information related to different timestamps. First, take a look at the “getMTime()” method listed below, which returns the last modification timestamp of a given directory element: $dirProc=new DirectoryIterator('default_path/'); In this case, the “getMTime()” method used above simply returns the last modification timestamp of the current directory element, which displays the following results, based on the two text files that I used in the previous section: Last modification timestamp of current file is : 1149698631 All right, now that you know how to use the “getMTime()” method shown above, take a look at the following code. In this case, I’m referencing the handy “getATime()” method, which returns the timestamp of the last access to a given directory element. Its implementation is as follows: $dirProc=new DirectoryIterator('default_path/'); As you can see, the above example illustrates a basic approach for how to use the “getATime()” method that I mentioned earlier. In particular, the script loops over the selected directory and displays the last access timestamps of both directories and files contained within the directory in question. Based on the logic applied by the prior example, the outputted results are listed below: Last modification timestamp of current directory is : 1150153955 As you may have realized, the “getATime()” method that you learned previously is not difficult to grasp, so let me show you another one which can be handy for retrieving the inode timestamp of a given directory element. Its implementation is as follows: $dirProc=new DirectoryIterator('default_path/'); Just in case you’re wondering what the term “inode” means, let me tell you that it’s short for “Index Node,” that is the sector of the hard disk that contains information about a specific directory or file, such as its name, permissions, etc. Okay, now that you understand the word "inode," take a moment to examine the output generated by the script listed a few lines above: Last inode modification timestamp of current directory is : 1149698503 As you’ll realize, after studying all the previous examples, the “DirectoryIterator” class has been provided with a great package of timestamp-related methods that suit the most common requirements of a web application that works intensively with the file system. The process is reduced to selecting the appropriate method that best fits your needs. At this point, we’re almost done for now. Nevertheless, there’s still one more section that I’d like you to read before you get too tired, because it’ll show you how to use two concrete methods called “getPath()” and “getPathName()” respectively. As you’ll see, they’ll allow you to retrieve the corresponding path of any directory element, so jump straight into the following section. I’ll be there, waiting for you.
blog comments powered by Disqus |
|
|
|
|
|
|
|