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

os and subprocess not finding binaries on Windows 10 anymore

Okay so my best guess currently is that I've severely screwed up my python environment somehow and I have no idea how. First off, I have tried uninstalling and reinstalling (actually upgrading from 2.7.14 to .15) python to no avail. the problem…
TheKewlStore
  • 304
  • 1
  • 6
2
votes
1 answer

AttributeError: 'module' object has no attribute 'exist'

I want to check if a file exists and if it does give the folder i create with mkdir the next higher number. Somehow I get the Error: AttributeError: 'module' object has no attribute 'exist' I do not understand why that os function does not work for…
Mauritius
  • 265
  • 1
  • 8
  • 23
2
votes
1 answer

rename the files with same names in different folders

I want to copy all the images in different folders into one folder. But the issue I am facing is files in different folders have same names e.g Folder: A123 Front A123 Black.jpg , A123 Pink.jpg , A123 Red.jpg Folder: A123 Back A123 Black.jpg , …
Ayyan Khan
  • 507
  • 2
  • 12
2
votes
2 answers

Try block catches wrong exception

I'm trying to create a folder, handling the different errors (FileExistsError if the folder already exists and OSError if the folder's name contains illegal characters), but Python seems to always choose the first except block when catching an error…
KanarchiK
  • 33
  • 3
2
votes
0 answers

Read files in Python based on their semantic numbering

I'm trying to iterate over files in a directory using the following command in python 3.6: for filename in os.listdir(my_dir) My files are numbered incrementally, like out1, out2, ...,out10, out11, .... Unfortunately, iteration over the files using…
Tina J
  • 4,983
  • 13
  • 59
  • 125
2
votes
3 answers

Can we get the timestamp information with os.listdir in Python (like ls -l)?

I contact an SFTP server and show files based on the modified timestamp. Currently, it is done using something like: files = os.listdir(SFTP) Loop over files and get the timestamp using os.stat. Sort the final list in Python. This looping in Step…
Nishant
  • 20,354
  • 18
  • 69
  • 101
2
votes
2 answers

Is there any equivalent of chgrp -R in python?

I want to change the group name of one directory recursively, I am using os.chown() to do that. But I can not find any recursive flag like (chgrp -R) in os.chown().
Fuji Komalan
  • 1,979
  • 16
  • 25
2
votes
1 answer

Why os.remove() or shutil.move() can only move part of files

I want to randomly choose 10 images from the training dataset to be the test data. If I only copy the selected data to the destination path, it works. But if I want to remove the source data, it can only remove some of them. I tried both os.remove()…
Molly Huang
  • 89
  • 2
  • 6
2
votes
1 answer

How to PIPE the output from a subprocess.Popen, while communicating to it at later point?

Okay, here's what I need to do. I'm trying to PIPE the output from Popen, to display it in real time. However, I need to communicate with my process while it is running to send inputs. The 1st string in the list exec_str_list contains the 1st shell…
codingCoffee
  • 444
  • 1
  • 6
  • 16
2
votes
0 answers

Rename a directory after extracting zip archive uploaded by user

I'm trying to rename the directory after extracting it in a temporary directory.The archive upload by user. What I mean, User will upload a .tar OR .zip file then I will make a temporary directory and extract user's file into that directory, now I…
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150
2
votes
4 answers

python prints folders and sub folders when only folders needed in python

I am making a program that prints all the folders over 90 days in python. Here is my code: import os from datetime import date from Tkinter import * import Tkinter, Tkconstants, tkFileDialog old_dirs = [] today = date.today() home1 =…
Bill
  • 515
  • 1
  • 4
  • 15
2
votes
4 answers

python os.listdir hitting OSError: [Errno 13] Permission denied

I'm trying to use os.listdir to grab a list of subdirectories but am running into an issue when I'm lacking permissions for one of these subdirectories. I can not gain permission so I'd like to continue as gracefully as possible. Ideally, I'd be…
Ian Panzica
  • 334
  • 1
  • 6
  • 20
2
votes
2 answers

Unable to create a directory with os.mkdir though it doesn't exist

I tried to create a directory with os.mkdir, but it raised FileExistsError. >>> import os >>> os.mkdir('test') Traceback (most recent call last): File "", line 1, in FileExistsError: [Errno 17] File exists: 'test' The file test…
SparkAndShine
  • 17,001
  • 22
  • 90
  • 134
2
votes
0 answers

'WindowsError: [Error 2]' while iterating files in C:\\ using 'os.walk'

I'm trying to make a program which iterates over every file in my C drive, checking the file's size and appending the size value to the list named 'filesizes_stored'. from matplotlib import pyplot as plt import os import…
lonelyjoe
  • 115
  • 2
  • 7
2
votes
4 answers

I don't understand how this "os.join" function is working? I am getting errors constantly and no reading on os functions is helping me

Here's the code sys.path.append( "../tools/" ) from parse_out_email_text import parseOutText #(its just another .py file that has a function I wrote) from_sara = open("from_sara.txt", "r") from_chris = open("from_chris.txt", "r") from_data =…
Amit Singh Parihar
  • 527
  • 3
  • 14
  • 23