I have to write a program which checks if a particular directory on my folder has any files (of a specific extension), and if it finds any files, it reads them one by one and loads data from them into a database.
This is the rough algorithm in my mind:
Using an infinite
while()
loop, continuously keep checking if the directory has any files of that particular extension (e.g. check if the directory has any*.xml
files). I can use the PHPglob()
function.If yes, then in a
foreach
loop, read data from each file and load it into the database.Once a file's data has been loaded, delete it.
My Question:
I will be constantly checking if there any .xml
files in the directory. This means that many times I will get a true
(meaning/saying "Yes, there are .xml
files in the directory") even for the files whose data is BEING loaded.
So once a file has been found in the directory, I need a check which checks if its data is in the process of being loaded into a database. How do I check that?
The process of data-loading is that I extract useful data from the file into a .csv
file and then use LOAD DATA INFILE
SQL query to load the data into my MySQL database.