t-orako
6/18/2019 - 6:39 AM

File operation

# file copy
import shutil
shutil.copy('./file.txt', './sample') 
# './sample/file.txt'
shutil.copy('./file.txt', './sample/file_rename.txt') 
# './sample/file_rename.txt'

# Get file name and file extension
ftitle, fext = os.path.splitext('/path/to/test.txt')
# ftitle: '/path/to/test'
# fext  : '.txt'

# Get file name from full-path
fname = os.path.basename('/path/to/test.txt')
# fname : 'test.txt'