0108 (64-Bit) DOWNLOAD: ➡ solidthinking environment.
I don't know what the problem is because every time I run the script, it is successful, but on the directory, I only have the.py files and no folders.
I have the list of the folders I want to download inside a file called 'folders_list.txt' and I have added this list to the Script.
I have tried renaming the.py files to.txt and the line above was changed to read as:
for root, dirs, files in os.walk(path):
for filename in files:
newfile = open(os.path.join(root, filename), 'w')
and I get an error that the new file is not writeable, but if I run the script on the folder itself, it works fine.
A:
The issue is that open(os.path.join(root, filename), 'w') doesn't create the directory and open a file in it. Instead, it opens a file and put it inside the root directory.
I would suggest instead to open the folder and make a directory:
new_root, new_dir = os.path.split(root)
new_dir = os.path.join(new_root, filename)
os.mkdir(new_dir)
with open(new_dir, 'w') as new_file:
new_file.write(filename)
Or instead, if you want to have all the files in a single directory, create them with open(os.path.join(root, filename), 'w')
For example:
import os
filename = os.path.join(root, filename)
os.mkdir(os.path.dirname(filename))
with
Related links:
Comments