# Buggy code
def check_watch_folder(self):
    if not os.path.isdir(self.session.config.get_watch_folder_path()):
        return

    # Make sure that we pass a str to os.walk
    watch_dir = self.session.config.get_watch_folder_path().encode("raw_unicode_escape")

    for root, _, files in os.walk(watch_dir):
        for name in files:
            if not name.endswith(".torrent"):
                continue

            try:
                tdef = TorrentDef.load_from_memory(
                    fix_torrent(os.path.join(root, name))
                )
            except:  # torrent appears to be corrupt
                self.cleanup_torrent_file(root, name)
                continue

            infohash = tdef.get_infohash()

            if not self.session.has_download(infohash):
                self._logger.info("Starting download from torrent file %s", name)
                dl_config = DefaultDownloadStartupConfig.getInstance().copy()

                anon_enabled = self.session.config.get_default_anonymity_enabled()
                default_num_hops = self.session.config.get_default_number_hops()
                dl_config.set_hops(default_num_hops if anon_enabled else 0)
                dl_config.set_safe_seeding(
                    self.session.config.get_default_safeseeding_enabled()
                )
                dl_config.set_dest_dir(
                    self.session.config.get_default_destination_dir()
                )
                self.session.lm.ltmgr.start_download(tdef=tdef, dconfig=dl_config)


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\core_manager.py", line 118, in on_received_state
RuntimeError: [Failure instance: Traceback: <type 'exceptions.ValueError'>: The filename, directory name, or volume label syntax is incorrect
run_tribler.py:85:start_tribler
Tribler\Core\Session.py:432:start
lib\site-packages\twisted\internet\defer.py:321:addCallback
lib\site-packages\twisted\internet\defer.py:310:addCallbacks
--- <exception caught here> ---
lib\site-packages\twisted\internet\defer.py:653:_runCallbacks
Tribler\Core\Session.py:429:load_checkpoint
Tribler\Core\Session.py:384:load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:570:load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:567:do_load_checkpoint
Tribler\Core\APIImplementation\LaunchManyCore.py:599:resume_download
Tribler\Core\TorrentDef.py:115:load_from_dict
Tribler\Core\TorrentDef.py:68:__init__
]

# Fixed code
def check_watch_folder(self):
    if not os.path.isdir(self.session.config.get_watch_folder_path()):
        return

    # Make sure that we pass a str to os.walk
    watch_dir = self.session.config.get_watch_folder_path().encode("utf-8")

    for root, _, files in os.walk(watch_dir):
        for name in files:
            if not name.endswith(".torrent"):
                continue

            try:
                tdef = TorrentDef.load_from_memory(
                    fix_torrent(os.path.join(root, name))
                )
            except:  # torrent appears to be corrupt
                self.cleanup_torrent_file(root, name)
                continue

            infohash = tdef.get_infohash()

            if not self.session.has_download(infohash):
                self._logger.info("Starting download from torrent file %s", name)
                dl_config = DefaultDownloadStartupConfig.getInstance().copy()

                anon_enabled = self.session.config.get_default_anonymity_enabled()
                default_num_hops = self.session.config.get_default_number_hops()
                dl_config.set_hops(default_num_hops if anon_enabled else 0)
                dl_config.set_safe_seeding(
                    self.session.config.get_default_safeseeding_enabled()
                )
                dl_config.set_dest_dir(
                    self.session.config.get_default_destination_dir()
                )
                self.session.lm.ltmgr.start_download(tdef=tdef, dconfig=dl_config)