I have a short Python script that opens a directory and puts all of the file names into a .txt file. I have tried a few ways to add a new line after each file name but cannot do it. I also want to convert the entire string to uppercase.
Here is what I have:
import os
#Path where the photos are stored
path1 = r"V:\DATABASES\0 Suspension\Suspensia Pictures"
#Variable to list all the files in the dorectory
file_dir = os.listdir(path1)
#Opens a new text file called Pics
newfile = open('Pics.txt','w')
#Writes lines in the file as a string
newfile.write(str(file_dir))
#Prints out all the file names
#print(file_dir)ode here
What I was thinking for the new line was to add print('\n')
after the newfile.write(str(file_dir))
line. However, that did not work.
As for the uppercase I am not sure where to put the .upper()
.
This is the current output:
X01BJ0041, X01BJ0050, X01BJ0058,
X01BJ0059, X01BJ0060,X01BJ0061,X01BJ0065
The output I am looking for:
X01BJ0006.JPG
X01BJ0007.JPG
X01BJ0008.JPG
X01BJ0026.JPG
X01BJ0036.JPG
X01BJ0037.JPG
X01BJ0038.JPG
X01BJ0039.JPG
X01BJ0040.JPG
X01BJ0041.JPG
X01BJ0050.JPG
X01BJ0058.JPG
X01BJ0059.JPG
Thanks For All The Help!