History and License - pathlib — Object-oriented filesystem paths — Python 3.11.3 ...
pathlib — Object-oriented filesystem paths. Basic use; Pure paths. General properties; Operators; Accessing individual parts; Methods and properties; Concrete paths. Methods; Correspondence to tools in the os module; os.path — Common pathname manipulations; fileinput — Iterate over lines from multiple input streams; stat — Interpreting ...
You're reading your paths from a file with a path per line, but you didn't strip the newlines from each string, so you're looking for files that include a newline character, . As your error message notes, the invalid path was:\n
'C:\\Test\\Project1\n' <-- Single slash followed by n; directories are double slash separated
Strip them off as you read, and you'll be fine:
for line in infile:
line = line.rstrip("\r\n") # Removes all trailing carriage returns and newlines
if line[0] == "R":
I guess you should use . Path.iterdir()
for pth in dir_.iterdir():
#Do your stuff here
I think you want:
for a in source_path.glob("*/*/*"):
if a.is_dir():
print(a)
From the documentation: The pattern means “this directory and all subdirectories, recursively”, whereas one ** is a text wildcard.*