Questions tagged [python-os]

The Python os module provides a portable way of using operating system dependent functionality. Use this tag for questions about using the "os" module.

The Python os module provides a portable way of using operating system dependent functionality.

Links

551 questions
2
votes
5 answers

How to get the nth subdirectory in Python?

Suppose I have a file known as xyz in a folder as shown below: Directory | |+ Subdirectory_n | |+ Subdirectory_(n-1) | |+ Subdirectory_(n-2) | …
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86
1
vote
1 answer

os.path.getmtime() inconsistent with time.time()

I'm trying to verify the time of most recent modification of a file and got to the following: print("before", time.time()) with open(file, "wb") as fh: fh.write(b"12345") print("after", time.time()) print("modified",…
Gerry
  • 1,938
  • 3
  • 18
  • 25
1
vote
1 answer

Is there a way to send a scan request to a printer using python OS library?

I'm currently building a text based console application to manage printing, scanning, etc but as usuall i have stumped my self and have had to come to stackoverflow for help. Any help is appreciated. I have imported the os library. import os But…
1
vote
0 answers

os.open with non-utf8 characters in file name

I am trying to copy a file from a source NFS volume to destination NFS volume. The file name has non-utf8 character and I am using bytes to open/read/write. Using os.open, the path opens fine on the source , but gives invalid argument error on…
CodeTry
  • 312
  • 1
  • 19
1
vote
1 answer

Way to Perform Tilde-Expansion on Every Path Evaluated by Python OS Module?

I'm running Linux, and would like for my project to replace the tilde character, '~', at the beginning of a path with my home directory, in the same way the terminal does. I've found a method of the os module that achieves this, known as…
MillerTime
  • 317
  • 2
  • 11
1
vote
0 answers

Reading files in batches and runnng my jupyter notebook

I have a jupyter notebook in which I read files from my desktop and then run my analysis on them resulting in a feature matrix (pandas dataframe). As my files are heavy, my laptop crashes if I read all the files (10+ gb) at once and run the…
1
vote
2 answers

How to print out a file's name with extension without the directory

I'm trying to format the following file: C:\Users\Johnny\Downloads\Misc\ticket.jpg to just print out only the file name and extension but I keep getting stuck. Is there a simple way to do this in Python3? import sys import sqlite3 import os conn =…
J Lee
  • 21
  • 3
1
vote
1 answer

Generator to read a large flat directory of files in alphanumeric order

I have a flat directory with large amount of files: myFolder: | 000001.csv | 000002.csv | 000003.csv ... | 100000.csv I need to read them in alphanumeric order and process them. Normal way to do it would be: files =…
Kamil Saitov
  • 175
  • 1
  • 13
1
vote
1 answer

How to check if a file is an executable in Python when os.acess() doesn't work?

I'm trying to get all the executables within a folder containing a bunch of libraries using a python script. To do so I set up the following: for libs in os.listdir(parent_dir): path = parent_dir + libs + "/" for root,dirs,files in…
Hashem HZ
  • 25
  • 4
1
vote
1 answer

Python program to rename files doesn't work on files on external drives

I wrote this program to rename all files in a directory to title case, and it works fine on files on the system. But when I use it to rename files on an external drive, the program executes successfully without any exceptions but the filenames…
v_ag
  • 278
  • 1
  • 5
  • 17
1
vote
1 answer

python csv.writerow() stops working when I add code below

The following code creates a CSV file with the headers I would like. import os import csv tempCSV = "03_26_09_41_21.BirdNET.results.csv" master_csv_path =…
1
vote
1 answer

Get the list of FOREGROUND apps using python psutil

Is there any way to list the Foreground apps (not processes) running on my computer? I tried using psutil but it shows me processes. But I just need to display visible apps. Here is the code I used - import psutil for process in psutil.process_iter…
1
vote
1 answer

How to check if a file exists in a folder starting with a substring and ending with a substring in Python

I wanna wait for a file to donwload, and I want to check on a folder while the file not exists I'll put a time untill the file finish the download. The problem is I wanna check if the file exists starting with a substring variable called…
1
vote
0 answers

Pyinstaller compiling is not working in Python

I am currently working on making a Python IDLE, I am giving an option to convert the python file to an executable file (.exe). But I get a Pyinstaller Error. I imported: import os import tkinter as tk import tkinter.ttk as ttk import tkinter.font as…
Gorzan
  • 69
  • 9
1
vote
2 answers

Custom naming of files in Python using pathlib library

With the os library you can pass a variable to os.path.join as a file name when creating the file. file_name = "file.txt" folder_with_files = os.getcwd() with open(os.path.join(folder_with_files,f"{file_name}.txt"),'w') as file: …
jharrison12
  • 150
  • 8