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
0
votes
1 answer

Converting code from Python 2.6.5 to Python 3

So I got this book Violent Python and well knowing just a little bit of Python 3 figured I get this to learn more about Network Programming with Python. Now realizing that the book uses an older version of python I wanted to learn to learn to get…
0
votes
0 answers

How can os.path.exists mismatch with os.makedirs?

There is a problem in my app that I experienced today, with saving files. The strange thing is that the code should be foolproof here. This is where I get an error: if not os.path.exists(os.path.abspath(os.path.join(file_path, os.pardir))): …
adamczi
  • 343
  • 1
  • 7
  • 24
0
votes
0 answers

checking if safari in macos process list

I'm wrote this code to check if 'bad_process' is running: bad_process_list=['iTerm'] c = os.popen('ps ea') #'ps aux' for complicated cases for smth in c: #make a timer to run fulltime for s in bad_process_list: if s in…
s1nceri7y
  • 1
  • 2
0
votes
2 answers

How can i get a path relative from an other?

I have a path1 relative from a path2 and I want to get this path1 from my script which isn't path1 or path2. I know the absolute path of path2.
Icetom54
  • 55
  • 2
  • 7
0
votes
2 answers

os.path operation in Django, change/join path issue

I'm getting the name of a file in Django after an Image save : path-> 'companies/92_dsa/log/Hydrangeas.jpg' as it is in database I do a clone of the file, an resize (is an image) and want to save the new file with a different name. I get the…
user3541631
  • 3,686
  • 8
  • 48
  • 115
0
votes
1 answer

Iterate through a directory structure and parse text files in Python

I'm working on a Python(3.6) project in which I need to parse some text files from a directory structure. Directory structure as: --easy(root dir) ----sub_dir -------another_sub_dir -----------description( another sub dir) ------------------…
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
0
votes
0 answers

function that browses every folder in a folder

i give a path to a function and i want this funtion to watch in every folder in this path and if there is a folder inside of a folder : watch in too. def function(path): for element in os.listdir(path): element_path =…
icetom 54
  • 63
  • 7
0
votes
1 answer

For loop throwing exception on file already deleted during os walk

I'm writing a script that walks through a directory and looks for files with the typical Windows installer extensions and deletes them. When I run this with a list (vs say checking for .msi or .exe), it breaks when going through the nested loop…
John Verber
  • 745
  • 2
  • 16
  • 31
0
votes
2 answers

Delete the 2nd to 9th file and loop for a timelapse Python

I have a folder of 1000 photos that I'd like to make a timelapse of. The photos are shot every 60 seconds, and I'd like to make a 10 minute interval timelapse. So I need to delete every 2nd to 9th photo and have it loop. For example, given 1000…
D500
  • 442
  • 5
  • 17
0
votes
1 answer

How to delete a specific number of files from many folders?

Let's suppose that I have a set of folders. I each folder I have more than 1000 files, I need to count 1000 in each folder than delete the rest, For example: Folder1 contains 1234 numpy files, I want to keep 1000 and delete the 234 files. I use …
user7979266
0
votes
1 answer

hdiutil creates a DMG when called directly but not from os.system()

EDIT: I have found that the problem is not with this code, it is actually a simple problem later on that acts in a similar fashion to shown here. I'm making a program that performs different stages of compression on a file. This part of the code…
user7450368
0
votes
3 answers

How do i replace \\ with / in python 3?

I have a part in my program that requires working with directories.My current code is: path = os.path.join('C:','Users',getpass.getuser(),'AppData','Roaming','Microsoft','Windows','Start Menu','Programs','Startup') Variable path prints:…
Mark5352
  • 13
  • 3
0
votes
1 answer

Syntax error trying to rename files

import os def rename_files(): file_list = os.listdir(r"file directory") print(file_list) for file_name in file_list: os.rename( file_name, file_name.translate(str.maketrans("","", "0123456789") …
0
votes
1 answer

Using os.walk to find total size of FTP server

I am trying to find the total file size of an ftp server with the following script: import os import ftplib from os.path import join, getsize serveradd = ("an.ftpserver.co.uk") # Define the ftp server print("Logging in to…
0
votes
1 answer

How to know when an application opened using python is closed?

I want to write a python program that would open an application and wait till it's closed and at last prints when it was closed. I wrote the below code but it prints the time right after it is opened. I used os.startfile(path_to_application) to run…
LearningEveryday
  • 207
  • 2
  • 5
  • 14