def File_Rename(source_file, target_file):
'Rename the source file name to that of the specified target name'
if File_Exists(source_file):
if File_Exists(target_file):
logger.debug('FILE NOT RENAMED - Target file: ' + target_file + 'EXISTS')
return False
else:
os.rename(source_file, target_file)
logger.debug('FILE RENAMED - Source_File: ' + source_file + '; Target_File: ' + target_file)
return True
else:
logger.debug('FILE NOT RENAMED - Source file: ' + source_file + ' DOES NOT EXIST')
return False
def File_Copy(source_file, target_file):
'Copy the source file to the target file'
if File_Exists(source_file):
if File_Exists(target_file):
logger.debug('FILE NOT COPIED - Target file: ' + target_file + 'EXISTS')
return 0
else:
shutil.copyfile(source_file , target_file)
logger.debug('FILE COPIED - Source_File: ' + source_file + '; Target_File: ' + target_file)
return 1
else:
logger.debug('FILE NOT COPIED - Source file: ' + source_file + 'DOES NOT EXIST')
return 0
def File_Delete(source_file):
'Delete the given file'
if File_Exists(source_file):
os.remove(source_file)
logger.debug('FILE DELETED - ' + source_file)
return 1
else:
logger.debug('FILE NOT DELETED - ' + source_file + ' - DOES NOT EXIST')
return 0
def File_Exists(file_name):
'Check whether the given filename exists and is actually a file'
try:
if os.path.exists(str(file_name)) and os.path.isfile(str(file_name)):
return True
else:
return False
except:
logger.debug("Error returned while checking if file exists")
return False
No comments:
Post a Comment
Please write your comments and suggestions