Python Batch Renames Files In Mac
I'm trying to write my first script. I have been reading about python but I am stock. I'm trying to write a script that will rename all the file names in a specific folder. this is
Solution 1:
In your example, when you get a list of files in a files_to_Change
directory, you get file names without the directory name:
>>>files = os.listdir('test_folder')>>>print files[0]
.com.apple.timemachine.supported
So in order to get the full path to that file, from whereever you're in your directory tree, you should join the directory name (files_to_Change
) with the file name:
import os
join = os.path.join
src = 'files_to_Change'
files = os.listdir( src )
for i in files:
old = i
new, ext = os.path.splitext ( old )
os.rename( join( src, old ), join( src, fileName ))
Post a Comment for "Python Batch Renames Files In Mac"