2

I have downloaded a csv file(ABC) using python and selenium and need to change the name of the file.

Input= ABC.csv #downloaded file with name ABC

Output= DEF.csv #New file with name DEF.

Any help is appreciated.

3 Answers3

0

try this

import os
os.rename('a.txt', 'b.kml')

From: How to rename a file using Python

nalm
  • 390
  • 2
  • 12
0

You can use os module to rename the file:

import os
os.rename('path to ABC.csv', 'path to DEF.csv')

Explanation:

rename first argument is the original file which needs to be renamed and second argument is the new name which it should be renamed. If the files are in current directory it will work by simply using the file names. Otherwise include the path where these files are there

More information at docs **https://docs.python.org/3/library/os.html#os.rename

0

Thanks All.. Used the below code and it is working fine. All others kept throwing the error as File not found. Used complete file path.

os.rename('C:\\Users\\pathname\\ABC.csv', 'C:\\Users\\pathname\\DEF.csv')