We are preparing our static files specially java script, css and images files to be moved to Amazon CDN. The thing we need to make sure here is that only those files that are in use should be moved. I was given a task to list all the js, css and images we are currently using in our application.
Initially I opened notepad and start writing down the names of those files.
Hehe, we don’t think out of the box.
The whole process was disgusting and I was feeling tired.
However working for a bit of time, an idea come to my mind, why not use computer to do the task for me.
And this is what I did.
Create .php file and write the following code in that file.
<form action=”" method=”post”>
<input type=”text” name=”path” />
<br>
<input type=”submit” value=”Submit” />
</form>
<?php
$pathName = $_POST['path'];
if($pathName){
$dir = new DirectoryIterator($pathName);
foreach($dir as $fileInfo) {
if($fileInfo->isDot()) {
// do nothing
} else {
echo $fileInfo->__toString().’<br>’;
}
}
}
?>
The code above did everything for me. Created a list of files in particular directory. I took print out of that list and crossed (x) files under construction.
In the first few lines I am creating form, adding input box for the directory path to be entered and submit button.
In the php code
- I get the path
- If path is not empty, I create an instance of DirectoryIterator available in PHP5, giving it directory path entered via input box.
3.Loop the $dir object and echo the result as string.