def removeFile(self, name): filePath = FH.createPathInDirectory(self.currentDirectory, name) exists = FH.checkIfFileExists(filePath) if not exists: return False os.remove(filePath) return True
def makeDirectory(self, name): newPath = FH.createPathInDirectory(self.currentDirectory, name) if FH.checkIfDirectoryExists(newPath): return False os.makedirs(newPath) return True
def changeDirectory(self, location): currentDir = self.currentDirectory newPath = FH.createPathInDirectory(currentDir, ''.join(location)) exists = FH.checkIfDirectoryExists(newPath) if not exists: return False self.currentDirectory = newPath return True
def getFileContent(self, file): pathToFile = FH.createPathInDirectory(self.currentDirectory, file) exists = FH.checkIfFileExists(pathToFile) content = [] if not exists: return None with open(pathToFile, 'r') as f: for line in f: content.append(line) return content
def getTextLinesFromBeginning(self, file, linesNum): path = FH.createPathInDirectory(self.currentDirectory, file) exists = FH.checkIfFileExists(path) content = [] if not exists: return None with open(path, "r") as f: for line in islice(f, int(linesNum)): content.append(line) return content
def printTwoFilesTogether(self, file1, file2): path1 = FH.createPathInDirectory(self.currentDirectory, file1) path2 = FH.createPathInDirectory(self.currentDirectory, file2) content = [] if not (FH.checkIfFileExists(path1) and FH.checkIfFileExists(path2)): return None with open(path1, "r") as f1, open(path2, "r") as f2: for line in f1: content.append(line) for line in f2: content.append(line) return content
def joinTwoFilesTogetherInThird(self, file1, file2, file3): path1 = FH.createPathInDirectory(self.currentDirectory, file1) path2 = FH.createPathInDirectory(self.currentDirectory, file2) path3 = FH.createPathInDirectory(self.currentDirectory, file3) content = [] if not (FH.checkIfFileExists(path1) and FH.checkIfFileExists(path2)): return None with open(path3, "w") as catFile, open(path1, 'r') as f1, open(path2, 'r') as f2: for line in f1: catFile.write(line) for line in f2: catFile.write(line) with open(path3, "r") as catFile: for line in catFile: content.append(line) return content
def __init__(self): self.currentDirectory = FH.getHomeDirectory()
def isRootLevel(self): atRootLevel = FH.isRootLevel(self.currentDirectory) return atRootLevel
def getPathFromCurrentFolder(self, destination): path = FH.createPathInDirectory(self.currentDirectory, destination) return path