Python Forum
How can I create a new folder, then create multiple new files in that folder?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I create a new folder, then create multiple new files in that folder?
#1
name = input ("what is your name?")
cupcakes = int(input ("How Many Cupcakes did you eat?"))
calories = 300
calMath = (calories * cupcakes)
totalCal = (0)

Create New Folder (name)
While totalCal < calMath
make a new file in new folder with (name+totalCal".txt")
totalCal = (totalCal + calories)

I want this while loop to keep making new files in the new folder until the loop is complete.
Reply
#2
have a look at os.mkdir() and os.mkdirs()
https://docs.python.org/3/library/os.html

if you prefer OOP - Pathlib also has Path.mkdir method
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  in c# create a loop counting from 0 to 5, consecutively Frankd 19 2,887 Apr-01-2025, 12:46 PM
Last Post: Frankd
  Create a new subclass in a Python extension based on an existing class voidtrance 6 1,580 Mar-25-2025, 06:37 PM
Last Post: voidtrance
  Correct/proper way to create save files snakes 0 544 Mar-11-2025, 06:58 PM
Last Post: snakes
  How can I create an animation like this? FoxoR 2 668 Jan-22-2025, 10:11 PM
Last Post: FoxoR
  Looping through each images in a give folder Python druva 1 1,286 Jan-01-2025, 08:46 AM
Last Post: Pedroski55
  I cannot create a virtual environment on visual studio code using python Willem_Aucamp316 2 4,349 Nov-27-2024, 02:20 PM
Last Post: menator01
  Please help me to create company budget mad_accountant 3 3,876 Oct-10-2024, 06:49 AM
Last Post: Pedroski55
  JenkinsFile to create a Python venv NikitaMathur 2 1,854 Sep-23-2024, 11:33 AM
Last Post: NikitaMathur
  How can I create this type hint. deanhystad 0 649 Aug-05-2024, 07:55 PM
Last Post: deanhystad
  How to create a moving average backward of a serie of sumbers? Frankd 5 1,749 Jun-25-2024, 04:52 PM
Last Post: Frankd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020