wiggst3r Posted June 23, 2008 Share Posted June 23, 2008 Hi I have a script that adds files to a folder, that I get from FTP. I download these files everyday and are txt files, but are iin CSV format. In this folder I currently have 3 files. 1.csv, 2.csv and 3.csv Rather than me renaming them everyday, I'm looking to write a script to auto-increment the filename. So i'm looking to loop through the files in the folder, If there is no filename which is 4.csv, the file that has been downloaded will be renamed to this. The next day, the file will be renamed to 5.csv etc Does anyone know the code to do this? Thanks Quote Link to comment Share on other sites More sharing options...
dmccabe Posted June 23, 2008 Share Posted June 23, 2008 something like: <?php $i = 0; while ($i <= 500) { $filename = '/path/to/'.$i.'.txt'; if (file_exists($filename)) { do stuff here } else { do other stuff here } $i++; } ?> Quote Link to comment Share on other sites More sharing options...
wiggst3r Posted June 23, 2008 Author Share Posted June 23, 2008 The test file is named download.txt How could i implement this into that piece of code? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.