rename files with spaces in a folder python

Solutions on MaxInterview for rename files with spaces in a folder python by the best coders in the world

showing results for - "rename files with spaces in a folder python"
Arianna
18 Jul 2016
1Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
2Type "help", "copyright", "credits" or "license" for more information.
3>>> import os
4>>> path  = os.getcwd()
5>>> filenames = os.listdir(path)
6>>> for filename in filenames:
7...     os.rename(os.path.join(path, filename), os.path.join(path, filename.replace(' ', '-')))
8...
9>>>
10