Python module implementing common pathname manipulations
Questions tagged [os.path]
502 questions
-1
votes
1 answer
Is there a way to combine more than 2 file paths at once?
I want to combine multiple file maths together, but I end up with nested stuff like os.path.join(os.path.join(“assets”, “imgs”), “something.png”). I was wondering if there’s a cleaner way.

NaniNoni
- 155
- 11
-1
votes
3 answers
How do I correctly use the os.path to locate a file stored in a specific folder?
I'm new to python and I've not used os.path that often, but as my projects grew and I started trying to integrate multiple folders together, I realized that it is probably best that I start using the os.path method.
I'm currently trying to get to a…

Obb-77
- 44
- 7
-1
votes
1 answer
Go up a directory using \.. in string path - Python os.path
I'm writing a post-job script for Thinkbox Deadline. I need the directory for the rendered frames from a finished Cinema 4D job.
In Cinema, we had the frames know to go up a few directories, then back down to a different location by using this…

Lucas Santos
- 1
- 1
-1
votes
1 answer
I am trying to get the size of a file with os.path.getsize but it prints out the size as bytes and I want to print it out in MB, any solutions?
I am trying to get the size of a file with os.path.getsize but it prints out the size as bytes and I want to print it out in MB, any solutions?
The code:
import os
from os import system
os =…

Krys
- 1
- 1
-1
votes
2 answers
Why the program can't find the file? python thanks
The code:
I'm trying to open this file but Python doesn't find it.
import os ,shutil, re , random
#categoria a caso
cat= random.choice(categorie)
string = str(input("Inseriisci nome utente e password\n"))
…

espo
- 11
- 1
-1
votes
1 answer
How to run a .txt with an .exe using python? ("dragging" .txt into .exe)
Me and my friend are trying to make a small program and we need to be able to do the same as if you would be dragging the .txt into the .exe, but with python.
The .exe is a converter which we need in order to read the .txt file.
We already can…

Jbu
- 3
- 3
-1
votes
2 answers
How to split or cut the string in python
I am trying to split the string with python code with following output:
import os
f = "Retirement-User-Portfolio-DEV-2020-7-29.xml"
to_output = os.path.splitext(f)[0]
print(to_output)
I have received an output…

Ankur1825
- 51
- 6
-1
votes
3 answers
Is there a way to shorten a file path on Mac (Python) and lessen the dataframes?
I already tried to use the os.path function.
For example, I have this file path:
/Users/GSteve_105/Documents/sites/Docs/Experiment/file1.csv
And I want to shorten it to
/file1.csv
So that I can then use the pd.read module to read the file. For…

GSteve_105
- 3
- 2
-1
votes
1 answer
Can a python script delete files on its own?
EDIT: I checked hidden files but only 1 appeared, still 3 missing
Hello in the beginning the script below work smoothly but after a couple of runs without errors my list files became smaller. Any chance I can restore these files?
from os import…

melindaou
- 29
- 1
- 5
-1
votes
1 answer
download from path 'file' save to 'other directory' python script issue
Need Help
Get input for where the file is located & tell the new directory to save downloaded URLs to
filepath variable assumes the text document with links is in the location of the python script - while this works, I would also like this to change…

archiemax
- 1
- 2
-1
votes
1 answer
Batch File Rename with Python
Below is my code to batch rename pictures inside a given directory
def multi_filename_change():
i = 0
files = askstring('Select your folder', 'Paste your directory path where your images are stored.')
for file in os.listdir(files):
if not…

BIGPESH
- 83
- 6
-1
votes
1 answer
how to check if path exist and copy folders and files using python
I have a python script that must check first if folder exist in giving path then if exist delete the existing one then copy the new one from the source. if does't exist just copy the new folder.
the problem is that in the source path if i have…

Dev Dj
- 169
- 2
- 14
-1
votes
3 answers
How to add (merge) multiple images in one directory
I have two types (A and B) of images in one directory and I want to add them together (not concatenate) them like this:
A1.jpeg + B1.jpeg = Merged1.jpeg
A2.jpeg + B2.jpeg = Merged2.jpeg
...
AN.jpeg + BN.jpeg = MergedN.jpeg
I don't know…

NatesM
- 25
- 1
- 7
-1
votes
2 answers
os.path.join gives incorrect output in certain cases
I want to merge two paths using os.path.join() function. Paths I want to merge are- '/Users/Tushar/Desktop/' and '/Exp'.
I was doing - os.path.join('/Users/Tushar/Desktop','/Exp') and
Expected output was - '/Users/Tushar/Desktop/Exp'
But I actually…

Tushar
- 511
- 5
- 7
-1
votes
3 answers
Loop remove files from folder which has some special text inside file
I have folder with many .txt files. I want to remove files from this folder which have words 'Best Regards' inside file.
I wrote simple loop but I still have problem I/O operation on closed file.
Here is my code.
import os, os.path
path =…

little girl
- 285
- 1
- 3
- 15