Пример #1
0
    def removeFile(self, name):
        filePath = FH.createPathInDirectory(self.currentDirectory, name)
        exists = FH.checkIfFileExists(filePath)
        if not exists:
            return False

        os.remove(filePath)
        return True
Пример #2
0
    def makeDirectory(self, name):
        newPath = FH.createPathInDirectory(self.currentDirectory, name)

        if FH.checkIfDirectoryExists(newPath):
            return False

        os.makedirs(newPath)
        return True
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
 def __init__(self):
     self.currentDirectory = FH.getHomeDirectory()
Пример #9
0
 def isRootLevel(self):
     atRootLevel = FH.isRootLevel(self.currentDirectory)
     return atRootLevel
Пример #10
0
 def getPathFromCurrentFolder(self, destination):
     path = FH.createPathInDirectory(self.currentDirectory, destination)
     return path