-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListDirFileNames.py
31 lines (25 loc) · 936 Bytes
/
ListDirFileNames.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import sys
import io
if len(sys.argv) is not 2:#takes in one argument for output textfile.
sys.exit("Error, script needs one command-line argument. (output.txt File)")
list=""#set up output name list
start=0#start of python script location string
end=len(sys.argv[0])#end of python script location string
#print(start)
#print(end)
#find python script name
while(sys.argv[0].find("/",start,end)!=-1):
#print(sys.argv[0].find("/",start,end))
start=sys.argv[0].find("/",start,end)+1
#create file name list excluding python script name
dirList = os.listdir("./")
for filename in dirList:
if(filename!=sys.argv[0][start:end]):
list=list+filename+"\n"
print("Now writing the following list of file names to %s" %sys.argv[1])
print(list)
#open output text file and write the file name list. Then close output file.
FILEOUT=io.open(sys.argv[1], "w", encoding='utf-8')
FILEOUT.write(list)
FILEOUT.close()