Documentation

IO

IO - object-oriented handling of files with three base classes: \Path, \Directory, \File. Additionally to them, other classes exist, including abstract ones for organizing a hierarchy.

Class Description Available from version
File Class for handling files.
Directory Class for handling directories.
Path Class for handling paths.
FileDeleteException Exception when deleing a file.
FileNotFoundException Exception when required file is missing.
FileOpenException Exception when opening file.
FileNotOpenedException Exception when failure to open the file.
InvalidPathException Exception on incorrect file path.
IoException Base class for all exceptions for file input-output.

The old core DeleteDirFilesEx receives path from site root and its counterpart method receives absolute path from sever root.

Please note : instead of $_SERVER["DOCUMENT_ROOT"] now you can use \Bitrix\Main\Application::getDocumentRoot.

Example

// D7
use Bitrix\Main\Application;
use Bitrix\Main\IO\Directory;
use Bitrix\Main\IO\File;

Directory::createDirectory(
    Application::getDocumentRoot() . "/foo/bar/baz/"
);
File::putFileContents(
Application::getDocumentRoot() . "/foo/bar/baz/1.txt",
    "hello from D7"
);
Directory::deleteDirectory(
    Application::getDocumentRoot() . "/foo/bar/baz/"
); 


© «Bitrix24», 2001-2022
Up