Class FolderAccessor

java.lang.Object
ch.nolix.base.environment.filesystem.FileSystemItemAccessor
ch.nolix.base.environment.filesystem.FolderAccessor

public final class FolderAccessor extends FileSystemItemAccessor
A FolderAccessor can access a folder.
Author:
Silvan Wyss
  • Method Details

    • forFolderPath

      public static FolderAccessor forFolderPath(String folderPath)
      Parameters:
      folderPath -
      Returns:
      a new FolderAccessor for the folder for the given folderPath.
      Throws:
      RuntimeException - if there does not exist a folder with the given folderPath in the file system on the local machine.
    • containsItem

      public boolean containsItem(String relativePath)
      Parameters:
      relativePath -
      Returns:
      true if the folder of the current FolderAccessor contains an item with the given relative path, false otherwise.
    • createFile

      public FileAccessor createFile(String relativePath)
      Creates a new empty file with the given relative path in the folder of the current FolderAccessor.
      Parameters:
      relativePath -
      Returns:
      a new FileAccessor for the created file.
      Throws:
      RuntimeException - if there exists already a file system item with the given relative path in the folder of the current FolderAccessor.
    • createFolder

      public FolderAccessor createFolder(String relativePath)
      Creates a new empty folder with the given relative path in the folder of the current FolderAccessor.
      Parameters:
      relativePath -
      Returns:
      a new FolderAccessor for the created folder.
      Throws:
      RuntimeException - if there exists alreay a file system item with the given relative path in the folder of the current FolderAccessor.
    • deleteFileSystemItem

      public void deleteFileSystemItem(String relativePath)
      Deletes the file system item with the given relative path from the folder of the current FolderAccessor if it exists.
      Parameters:
      relativePath -
    • getFileAccessors

      public IContainer<FileAccessor> getFileAccessors()
      Returns:
      new FileAccessors for the files in the folder of the current FolderAccessor.
    • getFileAccessors

      public IContainer<FileAccessor> getFileAccessors(String extension)
      Parameters:
      extension -
      Returns:
      a new FileAccessors for the files in the folder of the current FolderAccessor, that have the given extension.
    • getFileAccessorsRecursively

      public IContainer<FileAccessor> getFileAccessorsRecursively(String extension)
      Parameters:
      extension -
      Returns:
      new FileAccessor for the files in the folder of the current FolderAccessor, that have the given extension, recursively.
    • getFileAccessorsRecursively

      public ILinkedList<FileAccessor> getFileAccessorsRecursively()
      Returns:
      new FileAccessor for the files in the folder of the current FolderAccessor recursively.
    • getFileSystemItemAccessors

      public IContainer<FileSystemItemAccessor> getFileSystemItemAccessors()
      Returns:
      new FileSystemItemAccessors to the file system items in the folder of the current FolderAccessor.
    • getFolderAccessor

      public FolderAccessor getFolderAccessor(String relativePath)
      Parameters:
      relativePath -
      Returns:
      a new FolderAccessor for the folder with the given relative path in the folder of the current FolderAccessor.
    • openInFileExplorer

      public void openInFileExplorer()
      Opens the folder of the current FolderAccessor in a new file explorer.
    • readFile

      public String readFile(String relativePath)
      Reads the content of the file with the given relative path.
      Parameters:
      relativePath -
      Returns:
      the content of the file with the given relative path.
      Throws:
      RuntimeException - if there does not exist a file with the given relative path in the folder of the current FolderAccessor.
      RuntimeException - if an error occurs.