Questions tagged [os.path]
Python module implementing common pathname manipulations
504
questions
0
votes
0
answers
11
views
check updates on each subfolder of subfolders dcmp python
I am trying to build a back-up script in order to back-up all my pc to an external ssd(lost all my data 3 times by now).
It works great for the files and main folders but until now I am not able to ...
-2
votes
0
answers
20
views
Using os.path to check for a file daily/email if not present [closed]
I am a beginner and am looking for some help with automating a file check I do each day on various machines. At about 3pm, one or two .txt files are pushed to various machines. Right now, each machine ...
0
votes
2
answers
34
views
removing back dots dir from path's prefix
I have two paths.
path1 = /users/fida/data_lake/data/archived/09142023
path2 = /users/fida/data_lake/data/localpublished/SPTTES/End_to_End_Edit_Schedule/2022-08-03_11_22_03.kp
Output Im trying to get ...
-1
votes
1
answer
62
views
How to delete a file? Getting "The process cannot access the file because it is being used by another process" error
Update: I am not getting the error when hosting this online. Able to delete normally. Leaving this up incase there are any useful answers for running locally on windows pc.
Context: I download a pdf ...
0
votes
0
answers
44
views
How should I create a shortcut using Python and add it to the startup folder of the computer?
I am trying to create a Python code that I will later convert to a Windows executable (.exe) using PyInstaller. The code is supposed to display a message in a window, and add a Windows shortcut (.lnk) ...
0
votes
1
answer
75
views
python f-string and regular expression to generate customized path of a file in a directory
Given:
Files in a working directory:
WKDIR = "/scratch/project_2004072/Nationalbiblioteket/dataframes"
$ ls -l
...
-1
votes
1
answer
43
views
Naming a new folder path based on formula
I am trying to create new folders based on the date. How can I use the below code to add a date or specific string to a folder path to make the new file named as such?
MonthNum = pd.to_datetime('today'...
0
votes
0
answers
40
views
Django staticfiles.W004 warning when using os.path.join
I'm getting this warning:
?: (staticfiles.W004) The directory
'/home/user/Desktop/Projects/project/project/project/static' in the
STATICFILES_DIRS setting does not exist.
But only when I use this ...
0
votes
0
answers
88
views
"FileNotFoundError" in python after freezing the app
As a part of a python application, files in unmapped network drive are accessed. The script runs like a charm when running the .py file, but after freezing it as an .exe file using cx_freeze I am ...
2
votes
2
answers
64
views
Join the keys (file paths) of a dictionary to its items (items in that dictionary)
I have a dictionary that looks like this:
import os
file_names = {'C:\Data\Path1': ['item1.file', 'item2.file'],
'C:\Data\Path2': ['item3.file', 'item4.file']}
I'm trying to ...
1
vote
1
answer
26
views
os.path.join(*list) not working as expected when trying to convert a list to a path
I'm trying to convert this list:
a_list = ['c:', 'project_files', 'ProjA', 'B_Files']
into this path:
'c:\\project_files\\ProjA\\B_Files'
I'm using this:
a_list = ['c:', 'project_files', 'ProjA', '...
0
votes
0
answers
23
views
Why does os.path.dirname() think file after double slash is a directory? [duplicate]
Function dirname from Python module os.path should return directory name, so why it does it return file name when we use doubleslash?
path = "/a.php"
dirname(path) # result is /
vs
path = &...
0
votes
1
answer
27
views
Python reporting abspath as directly within CWD rather than the actual correct directory
I am attempting to code a small script to sort music tracks for me.
I'm running into a problem where the script looks for the file in the wrong place.
The user defines the directory to look for files ...
0
votes
0
answers
60
views
Python / Django - Safest way to normalize relative paths cross-platform?
Please note this question is about relative paths and must account for cross-platform functionality.
When a user uploads a file, I want to generate a timestamped path to it:
def get_filepath(instance,...
0
votes
1
answer
115
views
os.path.abspath() returning different results for same file
I am getting a different result for a file in os.path.abspath() when it is run in a unit test versus when it is run in the code being tested:
The code I am testing contains:
abspath = os.path.abspath(...
0
votes
0
answers
81
views
Call java .jar package in python using jpype
I'm trying to run a .jar from python, but I get the following error. I need help to solve it.
The python code is:
import jpype
import os.path
jvmPath = jpype.getDefaultJVMPath()
jarPath =os.path.join(...
0
votes
1
answer
69
views
Moving Files from directory to their own folders
I am struggling with the paths and directories to solve this problem. Basically, I have a long list of .lammps files in one directory. My goal is to copy each file and move it into its own folder (...
0
votes
0
answers
21
views
Adding relative path as aa variable
I want to get user input path and use it as a variable. But still struggle to use it right way. I put root variable for error_log creation in the folder by User input.
root = input("Enter path ...
1
vote
1
answer
195
views
How to set os.path correctly. Shows a different path when ran by systemd service
I have a python code with database file called pythontut.db (.py and db file on same folder). I used OS.path for path setting. When it is executed in thonny it works fine, I have created a systemd ...
2
votes
1
answer
400
views
Azure Databricks: Different result when comparing dbutils.fs.ls(PATH) vs os.path.exists(PATH)
I get different results when running dbutils.fs.ls(PATH) vs os.path.exists(PATH). I have removed the path in my azure blob so it should return False but with os.path.exists(PATH) is returns True. ...
1
vote
2
answers
32
views
Text issues with Abspath
I've been using
CURRENT_DIR=os.path.dirname(os.path.abspath(__file__)) and it has been working well.
However, for whatever reason when I have any path with a /N such as
tk.PhotoImage(f'{CURRENT_DIR}\...
0
votes
1
answer
448
views
Is there a way to get the working directory of a current python script if it is in One Drive?
My existing python script is in the One Drive and I want to get its path. I have tried all the solutions but none of them worked.
This code did not work at all.
import os
sys.getcwd()
It brought C&...
0
votes
0
answers
50
views
Python os.walk returns weirdly formatted root directory
I've written a program which uses tkinter's askdirectory to get a folder and then convert all images into another format. But I've noticed something weird.
The first step the program does is ask for a ...
0
votes
0
answers
28
views
Add a ".csv" extension to a file's name or path [duplicate]
Is there a recommended way to add a ".csv" extension, to a file's name or path, which you want to export as a csv?
I achieved it directly and naively, and I wonder if there is another way to ...
1
vote
2
answers
45
views
How can I find out which path os.path points to?
i am a web developer (php, js, css and ...).
i order a python script for remove image background. it worked in cmd very well but when running it from php script, it dosnt work.
i look at the script ...
0
votes
0
answers
19
views
Saving Multiple FTP Files to a Directory [duplicate]
I am trying to save multiple FTP files downloaded from a server to a subdirectory. I can pull and save the files but it saves to the current working directory.
When I execute the code below, I get an ...
0
votes
0
answers
228
views
How can I save my YAML file to my cwd or to a relative path?
I have the following code that generates a YAML file, for those not familiar, let's just say this is a csv file:
with open(f'/tmp/{source}-fields.csv') as csv_file:
reader = csv.reader(csv_file)
...
0
votes
1
answer
91
views
Iterating through all files in a root folder to search for specific files using os.walk()
I've tried to search previous questions but I couldn't figure out a solution to my problem.
I have a root folder that has many different subfolders and files. Each subfolder also has files within them ...
0
votes
2
answers
326
views
cv2.imread file with accent (unicode)
I am trying to load the following file: 'data/chapter_1/capd_yard_signs\\Dueñas_2020.png'
But when I do so, cv2.imread returns an error: imread_('data/chapter_1/capd_yard_signs\Due├▒as_2020.png'): ...
0
votes
1
answer
92
views
os.walk loop is not passing the readout of the last directory in the hierarchy to a list
I'm using os.walk and os.path.splitext to generate two separate lists of folder names and file names (w/o extension) located in a given disk drive of a Windows 10 system. For this purpose I'm using ...
1
vote
2
answers
305
views
os.path.getmtime when file doesn't exist
How do I set a variable to None or null when the file doesn't exist
for example:
lastModified = os.path.getmtime("/xyz.csv") if os.path.getmtime("/xyz.csv") is not None else null
...
0
votes
1
answer
292
views
How to create a Subdirectory with os.join.path in python?
So here is my issue:
def get_datasheets(self, build_id):
catalog = self._get_catalogue(build_id)
paths = []
for key, value in catalog.items():
if "data_sheets&...
0
votes
0
answers
132
views
Did os.path.expanduser( '~' ) get broken between Python 3.6 and Python 3.9 under Windows?
Here is the little script.py I ran
`
import sys
import os
if "__main__" == __name__:
def main() -> int:
print( "HOMEDRIVE: {0}".format( os.environ["HOMEDRIVE"]...
0
votes
0
answers
20
views
unable to iterate over a path using fabric module
I want to iterate over a folder to remove server and get the files I want to remove, below is the code i've written, but it's giving me the error:
File "script.py", line 13, in <module&...
0
votes
1
answer
101
views
Directories containing .jpg files were converted to binary files [shutil]
Update:
Basically, I want to divide a large folder into 2 groups.
The large folder is made up of 120 subfolders. An example subfolder name would be n02085620-Chihuahua. n02085620-Chihuahua has 152 ....
-1
votes
1
answer
54
views
python use os.path.join to take specific location
I need to save a folder called D:\MyPc if the hostname is MyPc
name_file = open("D:/Others/name.txt" , "r")
data = name_file.readline()
name_file.close()
print(os.path.join("D:...
0
votes
1
answer
25
views
Creating folders in a directory using variables (os.path)
I'm feeding my code lines from a txt file and using that to determine folder names.
import os
folderdir = r'C:\Users\myname\Documents\Folders'
txtfile = r'C:\Users\myname\Documents\foldernames.txt'
...
0
votes
2
answers
88
views
os.path.basename(file) vs file.split("/")[-1]
I need to extract seq_00034 from a file path like
file = "/home/user/workspace/data/seq_00034.pkl"
I know 2 ways to achieve it:
method.A
import os
seq_name = os.path.basename(...
-1
votes
2
answers
74
views
Split pathname in python [duplicate]
I'm trying to rename a filename with python. the thing is, the filename has a specific amount of characters, 48 to be exactly, and i need to split this name into some variables, like split the file ...
1
vote
1
answer
195
views
Why does os.path.realpath convert c:\windows\system32 into c:/windows/syswow64?
If we take a look to https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve source code we can see the routine is calling behind the curtains https://docs.python.org/3/library/os.path....
-2
votes
1
answer
175
views
Move files to folder made by user input with the same name
I have a directory containing the following:
name.xlsx
I use the following code to have a user input names for the folder(s) they would like to create in that directory.
dirPath = ‘dir_path’
naFold = ...
0
votes
1
answer
38
views
Make comparison of folders more efficient by opening one subfolder one at a time
I am comparing two folders containing images (Folder A and Folder B) for the purpose of identifying duplicates in Folder B. The comparison method is OpenCV's SIFT.
My original code stored the SIFT ...
0
votes
1
answer
190
views
Using Python os.walk or os.path to build an XML file based on subdirectory file contents
Let me try to describe this as simply as possible.
Problem: Workspace.xml is read by an IDE in order to load files into it's directory tree. We recently started adding "Package" sub-...
0
votes
0
answers
27
views
Shutil Move Dir Goes Missing
I am trying to write a short script to make some common tasks I do easier. The goal of the script is that I can point it toward a directory that has a bunch of folders within it. For the sake of my ...
0
votes
1
answer
163
views
How can I fix path.join error? It's not accepting the output of a function, even when typecast
I'm trying to write a simple script that organises image files based on their label, (given by a separate csv file -- this has been imported as a list called 'trainLabels15list').
import shutil
import ...
0
votes
1
answer
245
views
Saving files to different folder
I´m trying to save converted excel files from different paths, to the same folder.
How can I pass the path to the function correctly?
Now what is happening is that it is attaching the original path to ...
0
votes
1
answer
1k
views
os.path.exists() say False [duplicate]
I'm trying to make a code that downloads a file if it doesn't exist
import requests
from os.path import exists
def downloadfile(url):
if exists('file.txt')==False:
local_filename = url....
0
votes
0
answers
107
views
How to copy a file to mapped network drive with python
I'm trying to copy files from a folder in my C drive to a mapped network Drive (Z) and am receiving an error using shutil.copy, can someone please tell me where I'm going wrong? Thanks! Here's the ...
-1
votes
1
answer
322
views
Is there a way to combine more than 2 file paths at once? [duplicate]
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.
2
votes
1
answer
443
views
pathlib.Path('C:').absolute().is_absolute() returns False
Issue:
>>> from pathlib import Path
>>> Path('C:').absolute().is_absolute() # Is 'C:' absolute if we try to make it with pathlib?
False
>>> os.path.isabs(os.path.abspath('...