Re: Directory in Windows



In <1114885529.537692.178620@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, custard_pie
wrote:

> Here's my code
> ========================================================
> filelist={}
> def listFiles(self, dirName, filesInDir):
> for fname in filesInDir:
> if os.path.isfile(fname):

`fname` contains just the file name without the path to the file. So this
gives `False` for every file name except if there's a file with the same
name in the current working directory.

> key = os.path.join(dirName, fname)
> stats = os.stat(fname)

Same problem with `stat()`. Move the assignment to `key` up and use that
to check with `isfile()`/`isdir()` and `stat()`.

> filelist[key] = (stats[stat.ST_MTIME], stats[stat.ST_SIZE])
> os.path.walk(string.strip(self.path.get()), listFiles, None)
> print filelist
> =======================================================

Ciao,
Marc 'BlackJack' Rintsch
.



Relevant Pages

  • Re: Directory in Windows
    ... def listFiles(self, dirName, filesInDir): ... os.path.walk), listFiles, None) ...
    (comp.lang.python)
  • rubyinline
    ... general purpose comment code block runner. ... def run_eval ... code, offset = extract_block(fname) ... eval code, TOPLEVEL_BINDING, File.basename, offset ...
    (comp.lang.ruby)
  • Re: Ruby Compressor (little long)
    ... > I have need to distribute applications to customers. ... > def require ... > fp = File.join(path, fname) ... > # write header data - fname, ...
    (comp.lang.ruby)
  • Re: Ruby Compressor (little long)
    ... have every right to the source code, but when it is installed we do ... def require ... fp = File.join(path, fname) ... # write header data - fname, ...
    (comp.lang.ruby)
  • Re: regex problem with re and fnmatch
    ... for root, dirs, files in os.walk: ... if re.match(pat + '$', fname): ... def find_it: ...
    (comp.lang.python)