Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- os.chdir('/students/u6431023/comp1730/lab8')
- fileObj = open("sample.txt")
- def main():
- #printLinesBackwards(fileObj)
- print(filesInDir('/students/u6431023/comp1730/'))
- def countLinesInFile(file):
- posStart = file.tell()
- numLines = sum(1 for line in file)
- file.seek(posStart)
- return numLines
- def printLinesBackwards(file):
- lines = []
- num = countLinesInFile(file)
- for i in range(num):
- lines.append(file.readline())
- for i in range(num-1, -1, -1):
- print(lines[i])
- def filesInDir(dirAddress):
- if os.path.isdir(dirAddress):
- os.chdir(dirAddress)
- files = []
- for obj in os.listdir():
- print ('obj',obj)
- if os.path.isfile(obj):
- files.append(obj)
- elif os.path.isdir(obj):
- print ("why aren't ihere?")
- files.extend(filesInDir(obj))
- else:
- print(obj)
- return files
- if True:
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement