I have a requirement where i need to poll a directory for any .csv files. I have an external process which would put .csv files to that directory.
I need to listen to that directory and if it has any .csv files i need to process them and then delete them. I can put a while(true) statement to indefinitely see if any files are present in that directory.
Is this a good/standard way of doing it? Is there any better approach?
You should put at least a sleep into the while loop to prevent 100% CPU usage. And you should also put a break condition into the while loop with which you can stop it. For example you can use a boolean variable named stop to stop the loop. In this case you can write
"while(stop)" or you can put into the loop a "if (stop) break;" line. Maybe the first one looks better.