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

How to copy a file without using shutil.copy

My teacher gave us a task: I gotta create 2 folders: folder1 folder2 And i gotta add a text file to folder1 then append asmthg on it (iknow i use f = open("//Folder1//text.txt", mode = a, encoding = "UTF-8) then f.append("Hello World!") and then i…
-1
votes
1 answer

How to check file existence with python

I need to run the desired program in an application I am developing. I know I can run cmd commands with the code os.system in Python's built-in OS module. But when I run the start command with cmd and try to open an application that is not on the…
-1
votes
2 answers

Automated way to list files from multiple directories in Python

I need to create a list holding all files from multiple directories. I have all_dir which contains dir1, dir2, dir3.... Each directory contains multiple files ['text1.txt','text2.txt'...]. While I'm capable of creating list of single directories, I…
Girolamo
  • 326
  • 3
  • 11
-1
votes
1 answer

not able to open image in tkinter window, task was to make a gallery of images using os module but some error occurs as nothing is displayed on Window

The problem is my window is not showing any images that I want on the Tkinter window below is my code which I tried but some problems are occurring. the image folder is in the same folder in which the python file is and also some =thing with fp was…
sparsh
  • 135
  • 1
  • 1
  • 11
-1
votes
1 answer

Move individual files out of subfolders into main folder

I am looking to write a python script to move file1.pdf, file2.pdf and file3.pdf into the main folder 'test folder' test folder |__ folder 1 |___ file1.pdf |__ folder 2 |___ file2.pdf |__ folder 3 |___ file3.pdf result: test…
tedioustortoise
  • 259
  • 3
  • 20
-1
votes
1 answer

how could this be writtern better/simpler?

so the goal is to find the folder in a directory tree that has the greatest number of files and the folder that uses the most disk space. import os path = 'C:\\animal' highestsize = '' mostfile = '' totalsize = 0 totalfile = 0 for i in…
dimas28
  • 1
  • 1
-1
votes
2 answers

How to write np.argmax(array) to a text file?

I am using np,argmax to extract the position of the largest element in an array. I need to be able to convert this position - e.g. [x] into a string "[x]" so that I can write this to a text file. However it either doesn't write anything to the file,…
DTR98
  • 1
  • 3
-1
votes
2 answers

How to sort an int from a file

I have this code: import glob import os for file in glob.glob("./data/*.jpg"): lel=(os.path.basename(file)) lel = (os.path.splitext(lel)[0]) list1 = lel list1 = [int(x) for x in list1] list1.sort() print(list1) and it gives…
-1
votes
1 answer

Problem with writing a file on a certain path

I try to write the file to disk by specifying the path to the folder to save. But I get the error of reading the file by the specified path. FileNotFoundError: [Errno 2] No such file or directory:…
Jekson
  • 2,892
  • 8
  • 44
  • 79
-1
votes
2 answers

Take input from user using cmd after running Python script

I want to take input from the user after running my py script in Windows. A new cmd should pop up displaying a particular message like "Do you wish to continue [y/n]" and store this value in a variable in the py script and cmd should close…
aditya
  • 123
  • 2
  • 11
-1
votes
2 answers

Python list different directory without chdir

I have a directory with my .py file and I have another directory where I am writing files to. How can I get a os.listdir of the second directory without using os.chdir? Edit: Sorry seems like there are 2 parts to my implementation. My current code…
weasel
  • 534
  • 1
  • 5
  • 18
-1
votes
2 answers

Python changing directory without path

I would like to change the current work directory to the desktop without using os.chdir(path) since i want to use this code on different computer so the path will be different
-1
votes
1 answer

Why list comprehension doesn't work in case of list whih is result of os.walk function?

In result of os.walk function I get this list which contain names of files in folder: ['tr-02-10-18.pdf', 'tr-02-11-18.pdf', 'tr-02-12-18.pdf', 'tr-03-11-18.pdf', 'tr-03-12-18.pdf', 'tr-04-10-18.pdf', 'tr-04-11-18.pdf', 'tr-04-12-18.pdf'] My goal…
Sebastian
  • 23
  • 3
-1
votes
2 answers

Using Python and os.walk to find targets

I am currently working on a script to sift through filesystems (both Linux and Windows), to search for specific strings in text files. With what I have below I can select where I want to start, get the full paths to the files with the extensions I…
-1
votes
1 answer

Save files to a folder in python

I'm trying to save the products.json and index.html files to the folder I create in this snippet. How do I do this? It doesn't work as it stands. The files don't go inside of the directory, they just overwrite each other in the root directory as the…
Patrick
  • 374
  • 4
  • 21