Now you want to rename them in an orderly way, for example hostel1, hostel2, … and so on. Doing this manually would be a tedious task, but this goal can be achieved with the rename () and listdir () methods in the os module.
Method listdir lists all the contents of the given directory.
Syntax for listdir ():
list = os .listdir (`Src`): Where Src is the source to be listed out.
The following code will do the job for us. It loops through the lists of all images in the xyz folder, determines the destination (dst) and source (src) addresses, and renames using the rename module.
Below is the implementation:
The output of this code will look something like this:
Note. This code may not work in the online IDE because it uses external directory with image files.