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 Link to comment https://forums.phpfreaks.com/topic/111507-loop-and-increment-filename/ 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++; } ?> Link to comment https://forums.phpfreaks.com/topic/111507-loop-and-increment-filename/#findComment-572300 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? Link to comment https://forums.phpfreaks.com/topic/111507-loop-and-increment-filename/#findComment-572329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.