How to delete a file without specifying its extension? [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I've got files uploaded in a server, whose filenames are their id they have in my mongo database.
I've got a process that converts files from pdf to txt.
So, I want to delete the specified file without indicating it's extension.
Up to now, my code is as follows:
os.remove(os.path.join(app.config['UPLOAD_FOLDER'], str(document["_id"]) + ".txt"))

You can use glob to search folders with wildcards.
doc = str(document[“_id”])
glob.glob(‘{}.*’.format(doc))

Related

How Can I Find For Example *.mp3 Files From All Directories Of My System? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to find the absolute path of all of .mp3 formatted files from every directories of my system.
If you're using python, os.walk can help you.
Simple code like this can work:
import os
for data in os.walk('d:\\music'): # where to start searching
dir_path, folders, files = data
for f in files:
if f.lower().endswith('.mp3'):
print(os.path.join(dir_path, f))

Is their any path file method to delete itself if its a file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
do Path-file objects have any method to delete itself if its a file?
can we use os.remove?
method .rmdir() can't be used when correspond to file?
You can check if the path is file or directory with:
os.path.isfile("asd.txt")
os.path.isdir("asd")
And you can delete it with:
os.remove() will remove a file.
os.rmdir() will remove an empty directory.
shutil.rmtree() will delete a directory and all its contents.

how to change file directory path become reading file path [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I would like to read the current directory and make it become reading directory later
master1.filename = filedialog.askdirectory() # return current directory
and my problem will be the "/" , when the return result is using "/" and i need "\" in reading, and how should I make it ?
Use os.path.normpath(path) or other helpful methods in os.path module.

How to upload an HTML file into python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Im trying to write a python (2.7) program that can load a set of html files, search the files for certain variables and then extract the variables in json. Does anyone have an idea where to start, what commands or modules to import?
you might need beautifulsoup, this will help to parse the html.
You can open the html file using builtin python open funciton

Create a package python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I've created a TAR with some xml and classes, In another server i need to put those files in various directories, something like an installable, is possible?
Using CentOS
Thanks
You can easily just have a package.format and a python script that extracts from that format and moves the files to relative locations or an absolute location if you know that. Is that what you're looking for?
You can use zipfile for the extracting/compressing and shutil and os to move/delete/modify the files.

Categories

Resources