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
2 answers

Python - adding file names (not full paths) to list from directory and subfolders

This is for python 2. I have a chunk of code that is creating an object (dtry) containing three identical lists. Each list is all of the files (excluding folders) with a folder. This works, but I want to extend it to also work for subfolders. My…
askingaq
  • 75
  • 6
0
votes
2 answers

How to check if [dot]folders exist using python

I'm trying to make a python package and I want to take input from the user and save the info in a .example folder in the root directory so that I can access that info later. This is what I implemented but it's not working - def root_path(): …
0
votes
1 answer

python shutil.move moves directories with files fix

I was programming in python and I got something that I cannot fix. I have this code: import shutil import pathlib import os zdroj =(r'C:\Users\Acer\Desktop\New') cil =(r'C:\Users\Acer\Desktop\New2') files = os.listdir(zdroj) print(files) print…
ScreaMyCZE
  • 65
  • 1
  • 6
0
votes
1 answer

Renaming files os.rename() to timestamps returns weird string

So I am trying to rename some files to the time in their creation date using os.stat("file").st_stat. Then I pop the superfluous information, I only need the time because they are already sorted by date in dated folders. The code is kind of…
enpap-x
  • 15
  • 5
0
votes
2 answers

How do you use the os.rename() function in python 3?

I'm trying to rename the file names and extensions of all the files in a directory and move them to a new directory. I've read multiple post on how to do it but for some reason I haven't been successful and I've been stuck on this for 3 days now and…
0
votes
0 answers

Renaming a file missing underscore at few places

Before posting this, i just refer the link for renaming files in bulk, which is very useful to me while renaming a file from a given folder. Before renaming, i do a validation check on file name from a excel sheet, if file present then rename it to…
Kapi
  • 43
  • 8
0
votes
4 answers

How to access the last filename in a directory in python

I'm trying to loop through some files in a directory. If the filename has two specific strings together, then I'm supposed to open and read those files for information. However, if none of the files have those two strings, I want to print an error…
pjano1
  • 143
  • 1
  • 3
  • 10
0
votes
1 answer

Fixing os.remove error using with open causes string error

I have read over the cases previously asking about why os.remove is getting WindowsError: [Error 32] The process cannot access the file because it is being used by another process. I've tried using the with open(csvPath,"r") as csvData, but when…
Jason H
  • 168
  • 2
  • 12
0
votes
2 answers

os.listdir() lists data files but the corresponding assertion fails

I have the following code which throws an assertion error. os.listdir() lists my data files but there is still an assertion error. import os PATH_TO_FOLDER = 'LOCAL PATH TO MY DATA' assert 'data' in os.listdir(PATH_TO_FOLDER) import…
0
votes
3 answers

How to find unique files after removing files that have values in a particular list in Python?

I have the following files in a folder: "ABC" "ABC 10" "ABC 22" "ABC 30" "ABC L1" "ABC L2" "ABC 10 L1" "ABC 10 L2" "ABC 22 L1" "ABC 22 L2" "ABC 30 L1" "ABC 30 L2" "PQR" "PQR 10" "PQR 22" "PQR 30" "PQR X3" "PQR X4" "PQR 10 X3" "PQR 10 X4" "PQR 22…
Tom Kurushingal
  • 6,086
  • 20
  • 54
  • 86
0
votes
3 answers

Can't access directory using path

I have set up tensorflow GPU docker from https://tensorflow.org/install/docker. I am trying to load directory using import os library in Jupyter notebook on top of tensorflow GPU in Ubuntu. I can access import os library and fetch directory details…
Saurabh Chauhan
  • 3,161
  • 2
  • 19
  • 46
0
votes
1 answer

Retrieve files from only the third level of directory

I have a directory which has the following form : A/ : the root B/: The first level subdirectory which contains the following directories 01/ 02/ 03/ 04/ 05/ 06/ 07/ C/: third leve where each subdirectory from B/ (01/ or 02/ or 03/ or 04/ or 05/…
Taylor
  • 127
  • 1
  • 10
0
votes
1 answer

What are the return values of os.walk() in python?

I have a directory structure like this: dir/ └── subdir My code: import os for d in os.walk('dir'): print(d) I get the output: ('dir', ['subdir'], []) ('dir/subdir', [], []) My question is what are those trailing [ ]s ? There is 1 in the…
moctarjallo
  • 1,479
  • 1
  • 16
  • 33
0
votes
1 answer

xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0

I'm trying to parse a directory with a collection of xml files from RSS feeds. I have a similar code for another directory working fine, so I can't figure out the problem. I want to return the items so I can write them to a CSV file. The error I'm…
0
votes
1 answer

Error in word embedding with word2vec in windows

I am having problem while running this code in Windows10 word2vec = gensim.models.Word2Vec.load("word2vec.gensim") and getting this error word2vec = gensim.models.Word2Vec.load("word2vec.gensim") Traceback (most recent call last): File…