This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.walk has a bug on Windows
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: clovett, paul.moore, peter.otten, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2017-08-15 22:41 by clovett, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg300313 - (view) Author: Chris Lovett (clovett) Date: 2017-08-15 22:41
When I walk a directory recursively, it is tacking on an additional non-existant file from one of the subdirectories.  Here's the code:

    def copy_dir(self, src, dest):
        result = sftp.mkdir(dest)
        for dirname, dirnames, filenames in os.walk(src):
            for subdirname in dirnames:
                print("entering dir:" + subdirname)
                self.copy_dir(os.path.join(src, subdirname), os.path.join(dest, subdirname))
            for filename in filenames:
                print("copying:" + filename)

Here's the output:

entering dir:include
copying:CallbackInterface.h
copying:ClockInterface.h
entering dir:tcc
copying:CallbackInterface.tcc
copying:CMakeLists.txt
copying:darknet.i
copying:darknet.i.h
copying:darknet.obj
copying:darknet.py
copying:darknetImageNetLabels.txt
copying:darknetPYTHON_wrap.cxx
copying:darknetPYTHON_wrap.h
copying:darknet_config.json
copying:demo.py
copying:demoHelper.py
copying:OpenBLASSetup.cmake
copying:runtest.sh
copying:schoolbus.png
copying:CallbackInterface.h
copying:ClockInterface.h
copying:CallbackInterface.tcc

The last 3 files listed here doesn't exist, they are a repeat of the files found in the subdirectories.
msg300314 - (view) Author: Peter Otten (peter.otten) * Date: 2017-08-15 23:01
Read the documentation of os.walk() again. It already walks the complete directory tree starting with src. 

When you invoke it again by calling your copy_dir() method recursively you will of course see once more the files and directories in the respective subdirectory.
msg300320 - (view) Author: Chris Lovett (clovett) Date: 2017-08-15 23:27
Oh, my bad then. Apologies for the noise in your system.
History
Date User Action Args
2022-04-11 14:58:50adminsetgithub: 75397
2017-08-15 23:27:33clovettsetmessages: + msg300320
2017-08-15 23:10:59r.david.murraysetstatus: open -> closed
resolution: not a bug
stage: resolved
2017-08-15 23:01:57peter.ottensetnosy: + peter.otten
messages: + msg300314
2017-08-15 22:41:39clovettcreate