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

[[WinError 2]] The system cannot find the file specified: 'desktop.ini'

I'm trying to sort the files in a folder by the date they were created (with the most recently created first). The following commands: import os list1 = os.listdir(r'D:\Users\Pruthvi\Videos\Movies & TV Shows') print(list1) display the current…
Pruthvi Amin
  • 75
  • 2
  • 10
1
vote
1 answer

Permission denied with os.setuid() in uvloop

I need to run a subprocess in my main process as "nobody" user, code like this: # os.setuid(65534) # out the set_id work fine!! logging.warning(f"outside user: {getpass.getuser()}") # output: outside user: root def set_id() -> None: …
DustyPosa
  • 463
  • 2
  • 8
1
vote
1 answer

Does os.getuid() == 0 mean the root user?

In some of the code, I have conditions on os.getuid() == 0. Does this mean the script is checking if the user is root and needs "sudo"
Simplecode
  • 559
  • 7
  • 19
1
vote
1 answer

os.chdir() gives NoneType object

I am changing my working directory to make sure images are loaded from the right place. import os cwd = os.getwd() ##works fine newwd = os.chdir("C:\\Users\\Me\\Python\\Images") ##gives NoneType object I never had problems with that…
ISquared
  • 364
  • 4
  • 22
1
vote
1 answer

Are Python module attributes defined within a Python shell?

If I am using the __ file __ specifier in a Python script that is to be run inside Paraview's built in Python shell it should be able to interpret it correct? or any Python REPL for that matter. But if I were to directly use the __ file __ attribute…
Din Djarin
  • 13
  • 5
1
vote
1 answer

macOS - os.listdir returns double items which starts with "."?

Despite that the folder has two files (a.apk, and b.apk), os.listdir function returns four files such as ._b.apk, ._a.apk, a.apk, and b.apk. Where do the first two files come from? How can I prevent Python to list them? Software Stack: - OS: macOS…
talha06
  • 6,206
  • 21
  • 92
  • 147
1
vote
1 answer

Program running but file not opening using open() function

I am just learning about file manipulation and created a simple 'text.txt' file. This file, as well as my source code('files.py') share the same parent directory('files/'). I am trying to open the file: import os helloFile =…
Justin
  • 1,329
  • 3
  • 16
  • 25
1
vote
3 answers

Rename file with parent string if filename is a substring of list of strings

I have files in a directory and the filenames are a substring of a list of strings. I need to rename the files with the strings in the list filenames in "./temp" = aa.txt, bb.txt, cc.txt list_of_names = ['aa12.txt', 'bb12.txt', 'cc12.txt'] I…
robin_noob
  • 19
  • 1
1
vote
0 answers

os.system opens new window when executing pygame code

I am making a pygame reaction speed game for a project for computer science in which there is a menu, a maingame and a postgame appraisal with a score and an option to try again. I decided to seperate the three parts of the game into three different…
benj
  • 29
  • 3
1
vote
4 answers

how to capture only specific file types within a directory using glob

I am trying to use python's "glob" to grab various files using a wildcard AND NOT the path in which the files came. In this situation, I am trying to capture all files that begin with the name file_ within a directory. Though there can be…
bobparker
  • 45
  • 1
  • 1
  • 6
1
vote
2 answers

Iterate through folder/sub-directories and move found regex files into new folder

I´ve got a folder/sub-directories structure as follow: -main_folder -sub_1 322.txt 024.ops -sub_2 977.txt 004.txt -sub_3 396.xml 059.ops I´m trying to iterate with os.walk through…
Lucas Mengual
  • 263
  • 6
  • 21
1
vote
2 answers

Pass a file to Python via the Right-Click 'Open With' context menu in windows, to then open in another program

I use a piece of software that when you close, saves your current configuration, however, next time I open the software by clicking on a file associated with it, it tries to run that file through the same configuration, which I don't want. I have…
birdistheword99
  • 179
  • 1
  • 15
1
vote
2 answers

How do I rename multiple files in Python, using part of the existing name?

I have a few hundred .mp4 files in a directory. When originally created their names were set as "ExampleEventName - Day 1", "ExampleEventName - Day 2" etc. thus they are not in chronological order. I need a script to modify each of their names by…
user10883309
1
vote
0 answers

How find all the filenames when a list of file name fragments inputed using python glob?

I have a list of file name fragments, and I want to return a list of all the file names under a certain directory. I wrote this code to tackle this problem, but it turns out that is a rather slow solution. train_file_list = [] for p in…
yujuezhao
  • 1,015
  • 3
  • 11
  • 21
1
vote
2 answers

Python script unable to find locate downloads folder and open file

I am writing some automation code using python 2.7 and packages glob, webbrowser, and os to download links using google chrome. I have no issues downloading the file, but once downloaded, my script spits back that " 'C:/Users/UserName/Downloads*' is…
jod51
  • 111
  • 1
  • 2
  • 13