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

Using OS.walk and paramiko to move files to ftp server causing EOFError?

My goal is to walk through all files in a folder (and subfolders), check whether the file already exists on the ftp. If the file doesn't exist, put in in destination folder and if it does exist, archive the old file using rename and put the new…
dbell
  • 50
  • 10
0
votes
1 answer

simple python file search and record to csv

import os, csv f=open("C:\\tempa\\file.csv", 'wb') #write to an existing blank csv file w=csv.writer(f) for path, dirs, files, in os.walk("C:\\tempa"): for filename in files: w.writerow([filename]) running win7 64bit latest python,…
0
votes
2 answers

How to find .asc files 5 folders deep?

I have several .asc files hidden 5 folders deep. For example: main > Folder1a > Folder2a > Folder3a > Folder4a > myfile1.asc main > Folder1b > Folder2b > Folder3b > Folder4b > myfile2.asc main > Folder1c > Folder2c > Folder3c > Folder4c >…
Borealis
  • 8,044
  • 17
  • 64
  • 112
0
votes
1 answer

Get all nested directories in a folder python

This is the directory structure 10 files 2009 2010 11 files 2007 2010 2006 I am trying to get full path names of all the directories inside files import os x = os.walk('.').next()[1] print x # prints ['33', '18', '27',…
NEO
  • 1,961
  • 8
  • 34
  • 53
0
votes
1 answer

How do I pass Biopython SeqIO.convert() over multiple files in a directory?

I’m writing a python script (version 2.7) that will change every input file (.nexus format) within the specified directory into .fasta format. The Biopython module SeqIO.convert handles the conversion perfectly for individually specified files but…
PGilbert
  • 27
  • 7
0
votes
1 answer

Localization of Windows Pathname in Python or PyQT

I seaching now some days for a solution but can't find anything... I hope you can help. I need the translated windows path in python. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Calculator.lnk is in Windows Explorer on german…
Thiemo
  • 1
0
votes
1 answer

Applying script in subfolders

I cd into a folder and start python. I want to apply a script to fix filenames in a directory and in sub folders. import os for dirname, subdirs, files in os.walk('.'): os.rename(file, file.replace('\r', '').replace('\n', '').replace(' ', '_') …
0
votes
1 answer

List all HTML files in a directory python code not working

I am trying to list all HTML files in a directory using os.walk but it returning none instead of file names Here is my code def read_dirctory(): matches = [] for root, dirnames, filenames in…
user2085779
0
votes
3 answers

os.walk on non C drive directory

I know there are several posts that touch on this, but I haven't found one that works for me yet. I need to create a list of files with an .mxd extension by searching an entire mapped directory. I used this code and it works: import os …
user23469
  • 11
  • 1
0
votes
0 answers

Real time parsing from JSON to Python

I am trying to parse JSON files to Python using the json_load(). I have to do this on real time for a large number of files. Currently, I have 113 files and the parsing time is approx 15 mins (The files are 250 Kb each)! I have to use only certain…
Segmented
  • 2,024
  • 2
  • 23
  • 44
0
votes
1 answer

Iterate through subdirectories with os.walk in particular order

I'm trying to iterate through subdirectories of a top directory. For each subdir I want to walk down into it's subdirectories and then walk down into the files of the subdir. I've seen posts about os.walk but after spending a couple of morning train…
Punching Worms
  • 113
  • 1
  • 7
0
votes
3 answers

Need to modify files top to bottom using python's os walk. Generator object?

I need to modify some files using a python script, and I figure OS walk is the way to go about it. I need to modify everything under /foo/bar /foo/baz /foo/bat ....for example I've never used os.walk before, I read a bit about it and I see that it…
Zack
  • 13,454
  • 24
  • 75
  • 113
0
votes
0 answers

python os.walk for mobile devices

I'm trying to search files on my cellphone using os.walk(). It works perfectly with directories on my computer, but when I'm os.walk()ing on my cellphone (conected to my PC as a media device) it won't show any results. This is my function: def…
0
votes
2 answers

match files in sub directories only - python

I have a folder system like so: Root Mixtape 1 mp3s sub-dir/ mp3s Mixtape 2 mp3s sub-dir/ mp3s Mixtape 3 mp3s sub-dir/ mp3s I'm looking to create a list of all mp3 files (from the sub-dir's only) and then play a random mp3 from that…
Barry Jarvis
  • 329
  • 1
  • 8
  • 20
0
votes
3 answers

How can I make a Python script parse command line arguments like a Unix command?

I have a Python utility script that accepts arguments in the commandline and executes tasks against an open source search tool called Elasticsearch. But simply put, here is how it's currently being used: Myscript.py create indexname…
Horse Voice
  • 8,138
  • 15
  • 69
  • 120