Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Auto File PathNew to Visual Studio Code? Get it now.
Auto File Path

Auto File Path

JimmyFutureman

|
1 install
| (1) | Free
Automatically inserts and updates the file's relative path at the top of each file on create and save.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

README

Filename-Provider Extension

The "filename-provider" extension automatically adds a file path comment at the top of your files when they are created or saved in Visual Studio Code.

Use case

I build a lot with AI and use a repo flattener to help the AI understand the relationships between files. Including the filename at the top of each file when providing full files is a game changer in helping it stay focused and reference correctly.

Features

  • Smart Path Management: Automatically adds file path comments to the top of files
  • Duplicate Prevention: Detects existing correct paths and avoids adding duplicates
  • Auto-Update on Move: Replaces outdated paths when files are moved or renamed
  • Protected File Types: Skips files where comments would break functionality (JSON, YAML, etc.)
  • Extensive Language Support: Works with 30+ programming languages
  • Framework Ready: Works seamlessly with Next.js, NestJS, and other modern frameworks

How It Works

  1. On file creation or save, the extension checks the first few lines for an existing path comment
  2. If the correct path exists: Does nothing (prevents duplicates)
  3. If an outdated path exists: Replaces it with the current path (handles renames/moves)
  4. If no path exists: Inserts a new one at the top

Supported Languages

  • // style comments:

    • JavaScript, TypeScript, JSX, TSX
    • Java, C, C++, C#, Go, Rust, PHP
    • Swift, Kotlin, Dart, Scala
    • Objective-C, Objective-C++
  • # style comments:

    • Python, Ruby, Perl, R
    • Shell, Bash, Zsh, Fish, PowerShell
    • Makefile, Dockerfile, CoffeeScript
  • /* */ style comments:

    • CSS, SCSS, Sass, Less, Stylus
  • -- style comments:

    • SQL, Lua, Haskell, Elm

Protected File Types

The extension automatically skips files where comments would cause issues:

  • Config files: JSON, YAML, TOML, INI, .env files
  • Markup files: HTML, XML, SVG, Markdown
  • Template files: Handlebars, EJS, Pug, Jade
  • Special files: package.json, tsconfig.json, README.md, LICENSE, etc.
  • Build artifacts: node_modules, dist, build, .next, etc.

Examples

For a TypeScript file in Next.js:

// src/app/page.tsx

export default function Home() {
  return <div>Hello World</div>;
}

For a Python file:

# src/utils/helper.py

def process_data():
    pass

For a CSS file:

/* styles/main.css */

body {
  margin: 0;
}

Edge Cases Handled

  • Shebangs: Preserves shebang lines (e.g., #!/usr/bin/env node) and adds path below
  • File Moves: Automatically updates the path when you move or rename a file
  • Multiple Saves: Won't add duplicate paths on repeated saves
  • Mixed Comment Styles: Correctly handles different comment syntaxes per language
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft