-1

I have to make a script which creates a certain amount of subfolders in each main folder (dir1, dir2, and dir3). Then, inside of each subfolder, there has to be files (.txt.for example) been created constantly until I (the user) decides to stop the program. Right now, I can create subfolders (from 0 to 99) in each main folder, but I'm not sure how to create the .txt files. Any suggestions or ideas would be very much appreciated. Here's my code:

import os

folders = ["dir1", "dir2", "dir3"]
count = 0

for folder in folders:

    for count in range(100):
        subfolder = str(count)
        newfolder =  os.makedirs(os.path.join(folder, subfolder))

I'm trying to do something like this

with open("%s/01.txt" %count, "wa") as fh

so it goes to each subdirectory and create the file

1 Answers1

-1

You can simply open and write nothing. For example:

with open("01.txt", "w") as fh:
    fh.write("")

This means that you can also write stuff in the future, if necessary. It may not be necessary to .write(), but it improves readability.

PrinceOfCreation
  • 389
  • 1
  • 12