Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401]

(no description)

File Size: 131 lines (5 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

FileSystemHelper:: (6 methods):
  __construct()
  createFolder()
  createFileWithContents()
  deleteFile()
  deleteFolderRecursively()
  throwIfOperationNotInBaseFolder()


Class: FileSystemHelper  - X-Ref

Class FileSystemHelper
This class provides helper functions to help with the file system operations
like files/folders creation & deletion

__construct($baseFolderPath)   X-Ref

param: string $baseFolderPath The path of the base folder where all the I/O can occur

createFolder($parentFolderPath, $folderName)   X-Ref
Creates an empty folder with the given name under the given parent folder.

param: string $parentFolderPath The parent folder path under which the folder is going to be created
param: string $folderName The name of the folder to create
return: string Path of the created folder

createFileWithContents($parentFolderPath, $fileName, $fileContents)   X-Ref
Creates a file with the given name and content in the given folder.
The parent folder must exist.

param: string $parentFolderPath The parent folder path where the file is going to be created
param: string $fileName The name of the file to create
param: string $fileContents The contents of the file to create
return: string Path of the created file

deleteFile($filePath)   X-Ref
Delete the file at the given path

param: string $filePath Path of the file to delete
return: void

deleteFolderRecursively($folderPath)   X-Ref
Delete the folder at the given path as well as all its contents

param: string $folderPath Path of the folder to delete
return: void

throwIfOperationNotInBaseFolder($operationFolderPath)   X-Ref
All I/O operations must occur inside the base folder, for security reasons.
This function will throw an exception if the folder where the I/O operation
should occur is not inside the base folder.

param: string $operationFolderPath The path of the folder where the I/O operation should occur
return: void