Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Installing Modules
#11
OK Folkes, been doing some surfing and found this bit of code.
Added my own with statement and come up with this....

path = r"My Path"
path2 = r"My Path 2 with the file name of test2.text"
for child in Path(path).iterdir():
	if child.is_file():
		print(f"{child.name},\n{child.read_text()}\n")
		with open(path2,"a") as f:
			f.write(child.read_text())
I have the statement at the top of the scripts....
from pathlib import Path
This put all the files in the directory into 1 file.
How do I tell it to start a new file when the previous file has finished.
the file name would have to be changed for every file in the list.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Trouble installing modules/libraries and getting Notepad++ to show cyrillic letters Dragiev 6 3,895 Jul-24-2022, 12:55 PM
Last Post: Dragiev
  Installing Modules / packages Oshadha 1 2,254 Feb-05-2021, 08:04 PM
Last Post: Jeff900
  installing third-party modules shabux 5 4,863 Apr-13-2020, 12:41 AM
Last Post: Larz60+
  3rd Party Modules - Installing martyl 9 7,387 Jun-15-2018, 01:49 AM
Last Post: martyl
  pip and installing modules deep_logic 2 6,775 Jun-25-2017, 03:23 AM
Last Post: deep_logic
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 9,933 May-25-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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