Skip to content

Latest commit

Β 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 

Repository files navigation

mkfile


mkfile is a powerful, lightweight PowerShell utility that streamlines file and directory creation. Whether you're scaffolding new projects, organizing directories, or automating workflows, mkfile eliminates repetitive manual file creation with a single command.

Perfect for developers, DevOps engineers, and anyone who spends time setting up file structures manually.


πŸš€ Features

βœ… Create Single or Multiple Files - Add one file or dozens in a single command
βœ… Auto-Create Parent Directories - No more manual folder creation
βœ… Nested Path Support - Create deeply nested file structures instantly
βœ… Path Safety - Prevents accidental file creation outside your working directory
βœ… Simple & Intuitive - Minimal learning curve, maximum productivity
βœ… Cross-Friendly - Works with relative paths and complex directory structures
βœ… Lightweight - Zero dependencies, pure PowerShell


πŸ“‹ Requirements

  • Windows 10+ or Windows Server 2016+
  • PowerShell 5.1+ (included by default on all supported Windows versions)
  • Administrator Access (optional, depending on target directory permissions)

⚑ Quick Start

1. Load mkfile

. .\mkfile.ps1

2. Start Creating Files

# Single file
mkfile index.html

# Multiple files
mkfile index.html style.css script.js

# Nested structure (directories auto-created)
mkfile src/components/Button.tsx src/styles/Button.css

That's it! Files are created instantly.


πŸ“¦ Installation

Method 1: Direct Usage (Simplest)

  1. Download mkfile.ps1 from this repository
  2. Place it in your project directory
  3. Load it in your PowerShell session:
. .\mkfile.ps1

Method 2: Add to PowerShell Profile (Recommended)

Make mkfile available in every PowerShell session:

# Open your PowerShell profile
notepad $PROFILE

# Add this line to the file
. "C:\path\to\mkfile.ps1"

# Save and close

# Reload your profile
. $PROFILE

Now you can use mkfile from any directory!

Method 3: Add to System PATH

  1. Save mkfile.ps1 to a permanent location (e.g., C:\Scripts\)
  2. Add that folder to your Windows PATH environment variable
  3. Create a shortcut batch file in your PowerShell scripts folder

πŸ’‘ Usage Guide

Basic Syntax

mkfile [OPTIONS] <file_path> [<file_path2>] [<file_path3>]...

Common Use Cases

Create a Single File

mkfile README.md
mkfile index.html
mkfile config.json

Create Multiple Files at Once

mkfile app.js style.css index.html manifest.json

Create Files in Subdirectories

# Creates 'src' directory automatically
mkfile src/main.ts
mkfile src/index.tsx

# Creates nested directories
mkfile src/components/Button/Button.tsx
mkfile src/components/Button/Button.css
mkfile src/components/Button/index.ts

Mix Files and Directories

mkfile src/App.tsx public/index.html docs/API.md config/settings.json

View Version

mkfile -v
# Output: v1.1.0

View Function Info

mkfile -i
# Output: mkfile: A PowerShell function to create files.
#         Repository: https://github.com/mehedi-codes/mkfile
#         Author: mehedi-codes
#         Version: v1.1.0

🎯 Real-World Examples

Example 1: Bootstrap a React Project

mkfile public/index.html `
         src/App.tsx `
         src/index.tsx `
         src/App.css `
         src/components/Header/Header.tsx `
         src/components/Header/Header.css `
         .env.local `
         .gitignore `
         README.md

Example 2: Create a Node.js Project Structure

mkfile src/server.js `
         src/routes/api.js `
         src/middleware/auth.js `
         src/config/database.js `
         tests/server.test.js `
         .env `
         .env.example `
         package.json

Example 3: Organize Documentation

mkfile docs/Getting-Started.md `
         docs/API/Authentication.md `
         docs/API/Users.md `
         docs/API/Products.md `
         docs/CONTRIBUTING.md

Example 4: Setup a Python Project

mkfile src/__init__.py `
         src/main.py `
         src/utils/helpers.py `
         tests/test_main.py `
         requirements.txt `
         README.md `
         .gitignore

βš™οΈ Advanced Features

Auto-Create Directories

If a directory in the path doesn't exist, mkfile creates it automatically:

mkfile very/deeply/nested/structure/file.txt
# Creates all directories if they don't exist
# Output: Directory 'C:\...\very\deeply\nested\structure' created.
#         File 'C:\...\very\deeply\nested\structure\file.txt' created successfully.

Skip Existing Files

If a file already exists, mkfile skips it gracefully:

mkfile existing_file.txt
# Output: File 'C:\path\to\existing_file.txt' already exists.

Error Handling

mkfile provides clear error messages:

mkfile ../../../outside/project/file.txt
# Output: Error: Target path is outside the current working directory.

πŸ”’ Security

  • Path Containment: mkfile prevents creation of files outside the current working directory
  • Safe Permissions: Respects Windows file permissions
  • No Elevation Required: Works within user permissions (unless accessing restricted directories)
  • Error Reporting: Clear feedback on what went wrong

🀝 Contributing

Found a bug? Have a feature request? We'd love your help!

  1. Report an Issue
  2. Submit a Pull Request
  3. Check out open issues for ways to contribute

πŸ’¬ Feedback & Support


πŸ“Š Why mkfile?

Feature mkfile mkdir -p New-Item
Create Files βœ… ❌ βœ…
Auto-Create Dirs βœ… βœ… ❌
Multiple Files βœ… ❌ ⚠️ Verbose
Ease of Use ⭐⭐⭐⭐⭐ ⭐⭐ ⭐⭐⭐
Speed ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐

πŸ“ Version History

v1.1.0 (Current)

  • Improved error handling
  • Better directory creation logic
  • Enhanced path safety
  • Cleaner output messages

πŸ“„ License Information

This project is provided as-is for community use. See the repository for more details.

About

A Lightning-Fast PowerShell Function to Create Files & Directories in Seconds

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages