PhoenixKit.Pages.FileOperations (phoenix_kit v1.6.3)
View SourceFilesystem operations for Pages module.
Handles reading, writing, listing files and folders.
Summary
Functions
Returns the absolute filesystem path for a relative page path.
Copies a file to a new location.
Counts files and folders inside a directory recursively.
Creates a new directory.
Deletes a file or directory.
Checks if a directory exists at the path.
Checks if a path exists (file or folder).
Checks if a file (not folder) exists at the path.
Gets file info (size, modified time, etc).
Generates a unique filename by adding a number suffix if needed.
Lists all files and folders in a directory.
Moves a file or directory to a new location.
Reads file content.
Writes content to a file.
Functions
Returns the absolute filesystem path for a relative page path.
Copies a file to a new location.
Creates parent directories if they don't exist.
Examples
iex> FileOperations.copy("/hello.md", "/blog/hello.md")
:ok
Counts files and folders inside a directory recursively.
Returns a map with :files and :folders counts.
Examples
iex> FileOperations.count_contents("/blog")
%{files: 5, folders: 2}
Creates a new directory.
Examples
iex> FileOperations.create_directory("/blog")
:ok
Deletes a file or directory.
Directories are deleted recursively.
Examples
iex> FileOperations.delete("/hello.md")
:ok
iex> FileOperations.delete("/blog")
:ok
Checks if a directory exists at the path.
Examples
iex> FileOperations.directory_exists?("/blog")
true
iex> FileOperations.directory_exists?("/hello.md")
false
Checks if a path exists (file or folder).
Examples
iex> FileOperations.exists?("/hello.md")
true
Checks if a file (not folder) exists at the path.
Examples
iex> FileOperations.file_exists?("/hello.md")
true
iex> FileOperations.file_exists?("/blog")
false
Gets file info (size, modified time, etc).
Examples
iex> FileOperations.file_info("/hello.md")
{:ok, %{size: 1024, mtime: ~U[2025-01-01 00:00:00Z]}}
Generates a unique filename by adding a number suffix if needed.
Examples
iex> FileOperations.generate_unique_name("/hello.md")
"/hello-2.md" # if /hello.md exists
iex> FileOperations.generate_unique_name("/blog")
"/blog-2" # if /blog exists
Lists all files and folders in a directory.
Returns a list of maps with name, type (:file or :folder), and path.
Examples
iex> FileOperations.list_directory("/")
{:ok, [
%{name: "blog", type: :folder, path: "/blog"},
%{name: "hello.md", type: :file, path: "/hello.md"}
]}
Moves a file or directory to a new location.
Creates parent directories if they don't exist.
Examples
iex> FileOperations.move("/hello.md", "/blog/hello.md")
:ok
Reads file content.
Examples
iex> FileOperations.read_file("/hello.md")
{:ok, "# Hello World"}
Writes content to a file.
Creates parent directories if they don't exist.
Examples
iex> FileOperations.write_file("/hello.md", "# Hello World")
:ok