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
1
vote
1 answer

Python os.sendfile raises OSError: [Errno 38] Socket operation on non-socket

I am learning python os module and faced the issue with os.sendfile(...) method. Here's my code import os f1 = os.open('f1.txt', os.O_RDONLY) f2 = os.open('f2.txt', os.O_RDWR | os.O_CREAT) os.sendfile(f2, f1, 0, 100) # <-- Raises OSError: [Errno 38]…
Igor Belykh
  • 101
  • 5
  • 13
1
vote
0 answers

Windows Python path.join - The system cannot find the path specified

def env_variables(): dir_path = os.path.dirname(os.path.realpath(__file__)) os.environ["DIALOGFLOW_PROJECT_ID"] = "bot-fvji" os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.path.join(dir_path, "fvji0c3efb18f6e6.json") command =…
1
vote
0 answers

Pyfakefs not supporting os.renames?

Here's a simple piece of code I wanted to test: import os def move_all(firstPath, secondPath): for count, filename in enumerate(os.listdir(firstPath)): print('moving '+str(count) + ' '+filename) …
Honkou
  • 11
  • 2
1
vote
1 answer

how can i get the path plus the name of the first file in a folder and so on in python

I got this code and i need to take the first path of a file and the files name an have put it as a string from pathlib import Path from os import walk import os from posixpath import dirname f = [] jhon = r'C:\Users\ioshu\Desktop\you' for (dirpath,…
DanielMac
  • 21
  • 4
1
vote
1 answer

Is there a way to check for compile errors from running gcc inside python?

I want to do os.popen("gcc command") on a C file but if it fails for any reason I want to print a message and exit the program I don't want the error to print on the console just my message and exits. if os.path.exists(prog_path): command_result…
Kabdo
  • 11
  • 2
1
vote
1 answer

Accidently deletted my files when renaming them using python

I use Linux, I tried to rename all my image files in a folder using this code : import os i = 0 path = os.chdir("/home/saran/Documents/twitter content") for file in os.listdir(path): if file == "rename.py" : continue new_file =…
1
vote
3 answers

Python: Create a list of directories containing audio files

import os path = "." x = [] list_subfolders_with_paths = [] for dirs in os.walk(path): for dir in dirs: x.append(dir) print(len(x))
TINSEL19
  • 13
  • 3
1
vote
1 answer

Why am I unable to import my own os module?

I am using Python 3.10. I created a module os.py in a directory, my_dir. I am trying to access my os.py using import os, from my_dir directory. But it is loading Python's os module, not mine. I inserted my_dir in sys.path as a first element, but…
Arun
  • 59
  • 5
1
vote
0 answers

Python's os.copy_file_range not working with O_APPEND

I want to copy the content of a file 'from_path' to the end of another file 'to_path'. I wrote the code fd_from = os.open(from_path, os.O_RDONLY) fd_to = os.open(to_path, os.O_WRONLY | os.O_APPEND) os.copy_file_range(fd_from, fd_to,…
Calhau18
  • 11
  • 1
1
vote
1 answer

Incorrect path to my file when I try to restart it

I am trying to execute this: os.execv(sys.executable, ['python'] + sys.argv) The result I am getting: C:\Program Files\Python310\python.exe: can't find '__main__' module in 'c:\\Users\\user\\OneDrive\\Рабочий' As you can see, the path after the…
1
vote
2 answers

Loop through each subdirectory in a main directory and run code against each file using OS

Essentially what I'm trying to do is loop through a directory that contains multiple sub-directories and within those run code against each file in a for loop. The only start I managed to make was listing the directories but as I've rarely ever used…
AutoBotBot
  • 13
  • 3
1
vote
1 answer

How to determine the maximum number of processes that can be run per CPU core using python?

Using python 3.8.8 on a windows box, how to determine the maximum number of processes that can be run per CPU core? I followed some previously asked related questions like 1,2,3,4. Now the python docs on this subject suggest to use…
mnm
  • 1,962
  • 4
  • 19
  • 46
1
vote
2 answers

Import csv files based on condition from the folders that inside another folder

I would like to copy and paste csv files based on conditions from folders inside another folder. The main folder's name is “main”, and there are folders inside it, namely main_1, main_2, main_3,......, and main_45. There are also csv files inside…
helloworld
  • 89
  • 1
  • 9
1
vote
1 answer

Reading multiple json file using os method

I have like 100 json file in a folder and each json file contains information like student_id, student_nationality etc. How do I use readlines for each json file using os method? path_to_json = 'directory' json_files = [pos_json for pos_json in…
Tech
  • 65
  • 7
1
vote
1 answer

Having issue while implementing recursion

I'm trying to move the files from one source directory to another destination directory considering the destination directory has the same file and folder structure as the source directory. source directory: source/ ├── file1 ├── file2 ├── file3 ├──…
Shivam
  • 21
  • 6