7 examples of 'python delete file' in Python

Every line of 'python delete file' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
133def delete_file(path, name):
134 """ 删除文件 """
135 filename= '/'.join([current_app.static_folder, path, name])
136 if not os.path.exists(filename):
137 return False
138 os.remove(filename)
139 return True
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

76def delete_file(filename):
77 if os.path.isfile(filename) is True:
78 os.remove(filename)
45def delete_file(file_name):
46 print("Deleting File: " + file_name)
47
48 # Try to delete the file or folder
49 try:
50 if (os.path.isdir(file_name)):
51 shutil.rmtree(file_name)
52 else:
53 os.remove(file_name)
54 except OSError as e:
55 print("Error deleting file")
56 print(e)
47def delete_files(file_name):
48 '''
49 Common function to delete generated temporary files
50 '''
51 my_dir = "./"
52 for fname in os.listdir(my_dir):
53 if fname.startswith(file_name):
54 os.remove(os.path.join(my_dir, fname))
45def delete_file(bucketname, filename, aws_access_key='', aws_secret_key=''):
46 if not if_file_exist(bucketname, filename, aws_access_key, aws_secret_key):
47 return
48 bucket = get_bucket(bucketname, aws_access_key, aws_secret_key)
49 k = Key(bucket)
50 k.key = filename
51 bucket.delete_key(k)
124def delete_file(filename):
125 steamapi_file_delete((steamfolder + '/' if steamfolder else '') + filename)
39def Delete(self):
40 pass

Related snippets