PHP Directory Operations
Directory operations let you create, list, and manage folders programmatically. Essential for file organization and dynamic file systems!
Output
Click Run to execute your code
Create Directory
<?php
// Create single directory
mkdir('new_folder');
// Create nested directories
mkdir('path/to/folder', 0755, true);
?>
List Directory Contents
<?php
$files = scandir('.');
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
echo $file . "\n";
}
}
?>
Pattern Matching with glob
<?php
// Find all PHP files
$phpFiles = glob('*.php');
// Find all JPG images
$images = glob('images/*.jpg');
?>
Summary
- mkdir(): Create directory
- scandir(): List contents
- glob(): Pattern matching
- rmdir(): Remove empty directory
What's Next?
Next, learn about CSV Files - reading and writing comma-separated values!
Enjoying these tutorials?