Jhigs Jhigs - 2 years ago 114
Python Question

Python: Renaming first 5 files of a folder

I dont know if this can be done or not, but is there a way that I can rename only the first 5 files in a folder? I know that I can use the os.listdir() or os.walk() to walk through the entire folder, but I only need to rename the first 5 files. I am able to use a Regex to match the files, but the problem is is that there are other files that match the same Regex. Does anyone have any suggestions?
The file name takes the form of "Test Run 1 4-29-2016 2 07 56 PM".

Answer Source

You can limit the result from listdir:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download