Linked Questions
53 questions linked to/from How can I delete a file or folder in Python?
29
votes
1
answer
38k
views
How to remove a directory? Is os.removedirs and os.rmdir only used to delete empty directories? [duplicate]
Whenever I try to use them to remove dirs with things in them I get this error message
import os
os.chdir('/Users/mustafa/Desktop')
os.makedirs('new-file/sub-file')
os.removedirs('new-file')
"/...
5
votes
1
answer
7k
views
Python tempfile [Errno 66] Directory not empty [duplicate]
I need to process some file generated from db objects and after required process need to delete that directory with files.I have decided to use python templefile package. I have give it a try but ...
-4
votes
1
answer
2k
views
How to delete files inside hidden folder with python? [duplicate]
I want do delete a file, for ex. 'myfile.txt' that is stored under a hidden folder. Is it possible to do this in python?
thank you
3
votes
1
answer
354
views
How to delete the files after the concatenation with python? [duplicate]
Here's my code :
import glob
import pandas
import os
os.chdir("/filepath")
extension = 'xlsx'
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
combined = pd.concat([pd....
1
vote
0
answers
109
views
Is there one python function that removes files AND directories indiscriminately? [duplicate]
As far I can tell, there are separate APIs to remove folders and files in Python (os.remove and os.rmdir or shutil.rmtree). Isn't there one function library that does it all, no question asked, or do ...
0
votes
0
answers
62
views
Any way to remove the git repository using python [duplicate]
In my project I have used the python-git module to clone the repo.
but for the cleanup I have to remove the directory as well.
I am using the following method for cleanup but it did not work.
def ...
2
votes
0
answers
60
views
How to suppress a folder or a file with os module [duplicate]
Hey i wanted to know how to remove a folder or a file with the module os in python.
def remove_folder():
remoce_folder = str(input("What is the directory path of the folder: "))
How ...
0
votes
0
answers
36
views
How to Create a Bash Script to Remove .config/nvim Based on User Input in Python [duplicate]
Question: I have a simple Python script that prompts the user with a warning message. If the user responds with “yes,” I want to create a bash script that removes the .config/nvim directory. Here’s my ...
1142
votes
24
answers
1.1m
views
How do I remove/delete/replace a folder that is not empty?
I am getting an "access is denied" error when I attempt to delete a folder that is not empty. Newer versions of Python may also report a "directory not empty" error.
I used the ...
96
votes
2
answers
179k
views
Plotting networkx graph with node labels defaulting to node name
NetworkX is powerful but I was trying to plot a graph which shows node labels by default and I was surprised how tedious this seemingly simple task could be for someone new to Networkx. There is an ...
6
votes
3
answers
32k
views
Delete files that are older than 7 days
I have seen some posts to delete all the files (not folders) in a specific folder, but I simply don't understand them.
I need to use a UNC path and delete all the files that are older than 7 days.
...
11
votes
5
answers
27k
views
Python Script to detect broken images
I wrote a python script to detect broken images and count them,
The problem in my script is it detects all the images and does not detect broken images. How to fix this. I refered :
How to check if ...
6
votes
3
answers
5k
views
Draw more information on graph\nodes using PyGraphviz
I want to create a graph and draw it, so far so good, but the problem is that i want to draw more information on each node.
I saw i can save attributes to nodes\edges, but how do i draw the attributes?...
1
vote
3
answers
5k
views
Execute bash commands that are within a list from python
i got this list
commands = ['cd var','cd www','cd html','sudo rm -r folder']
I'm trying to execute one by one all the elements inside as a bash script, with no success. Do i need a for loop here?
...
-3
votes
2
answers
9k
views
Deleting a line from text file in python
I want to delete a specific line in a text file in python. for example, say in my text file I have:
Ben Walsh - 768
James Cook - 659
Jamie Walsh - 4359
Owen Perkins - 699
Dylan Thomas - 1574
...