Questions tagged [os.walk]

`os.walk()` is a Python function which serves to walk a directory tree.

With os.walk() you can walk a directory tree and get, for each of the subdirectories, a list of file names.

A simple example goes like

import os
for root, dirnames, filenames in os.walk('.'):
    for filename in filenames:
        print os.join(root, filename)
726 questions
0
votes
0 answers

Walk through dynamically changing folders

I have implemented os.walk a ton of times until now, and it worked super fine. But now, I need to implement os.walk on a folder, whose contents keeps on changing/updating every 10 secs (by another program). And, when I do os.walk on this folder,…
scorpion35
  • 944
  • 2
  • 12
  • 30
0
votes
1 answer

Only processing specific directories with os.walk() in python script

I have this python script that concatenates a classpath variable. It concatenates the directories of all the files that endwith a ".properties" extension as well as a ".jar" extension. However, some ".jar" files as well as ".properties" files are…
Doublespeed
  • 1,153
  • 4
  • 16
  • 29
0
votes
1 answer

walking directory in python to concatenate a classpath variable

I wrote a script to concatenate a variable called classpath_augment using python. I was able to successfully concatenate directories and the contained jar files to the classpath_augment variable, however, I also need to add to the classpath variable…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
0
votes
3 answers

Python directory searching and organizing by dict

Hey all, this is my first time recently trying to get into the file and os part of Python. I am trying to search a directory then find all sub directories. If the directory has no folders, add all the files to a list. And organize them all by…
Chuck
  • 207
  • 1
  • 5
  • 11
0
votes
2 answers

Python 3 `os.walk` is way slower than a simple `find -type d`

I need to find all git repositories in some folders. Previously, I used find . -type -d -name .git. Now I rewrote this in Python 3 and use os.walk. It seems to take way longer for it to traverse the tree than the simple find. How can I speed this…
Martin Ueding
  • 8,245
  • 6
  • 46
  • 92
0
votes
1 answer

Python - Present all files within a specific folder without the given folder

Using Python, I want to print all the files inside a given directory, without display the directory itself. I tried to use os.walk but it always print the directory. for root, dirs, files in os.walk(directory): for subFile in files: …
TidharPeer
  • 3,777
  • 3
  • 21
  • 32
0
votes
1 answer

Iterating over the values from a dictionary to replace file names in a directory

all. I have a csv file where I've arranged DNA sample IDs that I sent out to be sequenced in a 96-well plate. This is important to keep track of because when we get the plate back from the sequencing facility the chromatogram files are titled…
kitkor
  • 15
  • 5
0
votes
2 answers

Need 'if os.havefiles' like function for subfolder search in python

I need to os.walk from my parent path (tutu), by all subfolders. For each one, each of the deepest subfolders have the files that i need to process with my code. For all the deepest folders that have files, the file 'layout' is the same: one file…
BioInfoPT
  • 53
  • 3
0
votes
2 answers

Python: Copying a file with shutil

I'm trying to copy my places.sqlite info to my desktop with python. It is stored at users\username\AppData\Roaming\Mozilla\Firefox\Profiles\rh425234.default\places.sqlite However, what is want is to os.walk from \Profiles\ to \places.sqlite, and…
0
votes
1 answer

How can I ignore specific files when I am parsing a directory?

I am trying to parse this directory and I want to see all the txt files except for three specific names. With the code I have wrote I can get all of the text files in all of the directories. for root,dirnames,filenames in os.walk('D:/datast12'): …
UserYmY
  • 8,034
  • 17
  • 57
  • 71
0
votes
2 answers

Combine CSV file data to one CSV file

I have csv files spread around in multiple directories, each of the csv file has only one column containing data. What I want to do is read all these files and bring each file's column into on csv file. Final csv file will have columns with filename…
add-semi-colons
  • 18,094
  • 55
  • 145
  • 232
0
votes
1 answer

os.walk to find path to file issue (Python 2.7)

I've just starting using python 2.7 and was using the following code to ascertain the path to a file: import os, fnmatch #find the location of sunnyexplorer.exe def find_files(directory, pattern): for root, dirs, files in os.walk(directory): …
0
votes
2 answers

Creating many arrays at once

I am currently working with hundreds of files, all of which I want to read in and view as a numpy array. Right now I am using os.walk to pull all the files from a directory. I have a for loop that goes through the directory and will then create the…
anon
0
votes
1 answer

How to fetch a specific file or directory list using os.walk in Python?

I'd like to know if it is possible to retrieve by index number a specific file in a specific subfolder inside an os.walk class. I'd also like to know how can I list just the subdirs at a specific level inside the os.walk, for example just the…
user2066480
  • 1,229
  • 2
  • 12
  • 24
0
votes
1 answer

Downloading an arbitrary number of files from a URL with urllib2 in Python 2.7. Equivalent of "os.walk" for urllib2?

I'd like to download all of the files in a particular directory at a known URL. The names of the files won't necessarily be known, but their names will all contain a common keyword, and will have the same extension (.xml). Is there an equivalent of…