Windows Vista introduced support for dot-prefix filenames (like ".svn"), but the standard Explorer interface and CMD's rename
command block attempts to remove the primary filename portion. This creates problems when developers need to:
- Convert config files to dot-prefix convention (e.g., "config" → ".config")
- Maintain version control system files (like SVN's ".svn" directories)
- Create Unix-style hidden files in Windows environments
Using Command Prompt:
:: This WON'T work:
ren example.txt .txt
:: Use this PowerShell alternative:
powershell -command "Rename-Item 'example.txt' '.txt'"
Via PowerShell Directly:
# Works reliably in Vista SP2 and later
Rename-Item -Path "currentname.ext" -NewName ".ext"
Batch Script Solution:
@echo off
setlocal enabledelayedexpansion
:: Convert all files in folder to dot-prefix
for %%f in (*) do (
set "ext=%%~xf"
if not "!ext!"=="" (
powershell -command "Rename-Item '%%f' '!ext!'"
)
)
Using Robocopy (Vista's built-in alternative):
:: Requires creating temp folder
mkdir temp
robocopy . temp /MOV /NJH /NJS /NS /NC
ren temp\file.ext .ext
robocopy temp . /MOV /NJH /NJS /NS /NC
rmdir /s /q temp
Be aware of these technical constraints:
- NTFS filesystem handles these names correctly, but FAT32 may corrupt them
- Some backup utilities might skip dot-prefix files during operations
- Windows Explorer may display these files inconsistently
Converting Git ignore templates:
# Create initial file
echo "bin/" > gitignore_temp
# PowerShell rename
Rename-Item gitignore_temp ".gitignore"
# Verify creation
dir .gitignore
Remember that while Vista supports this behavior, proper implementation requires either PowerShell or creative workarounds with native tools.
While Windows Vista (and later versions) technically support files with dot-prefix names like ".svn" or ".gitignore", attempting to rename existing files to this format through conventional methods often fails. The system UI and basic commands don't make this transition easy. Here's how to bypass these limitations.
When you try to rename "example.txt" to ".svn" in Explorer, Windows throws an error about invalid file names. The command prompt's rename
command similarly fails. This occurs because:
- Explorer's rename validation rejects empty basenames
- CMD's rename command follows similar restrictions
- The Win32 API actually permits these names at lower levels
Method 1: Using PowerShell
The most reliable approach is using PowerShell which has direct filesystem access:
# PowerShell one-liner Rename-Item "example.txt" -NewName ".svn"
Or for batch processing:
Get-ChildItem | Where-Object { $_.Name -eq "oldname" } | Rename-Item -NewName ".newname"
Method 2: The Move Workaround in CMD
You can trick the command prompt using the move
command:
:: In Command Prompt move "example.txt" ".svn"
Note the quotes are essential for this to work.
Method 3: Direct Win32 API Calls
For programmers needing this functionality in applications:
// C# example using MoveFile [DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)] static extern bool MoveFile(string lpExistingFileName, string lpNewFileName); void RenameToDotFile(string originalPath) { string dir = Path.GetDirectoryName(originalPath); string newPath = Path.Combine(dir, ".newfilename"); MoveFile(originalPath, newPath); }
Watch out for these scenarios:
- Files with no extension (use trailing dot:
rename file "."
) - Network paths may require UNC-formatted names
- Some backup systems might ignore dot-prefix files
This capability is crucial when:
- Working with version control systems (SVN, Git)
- Creating Unix-compatible configurations on Windows
- Developing cross-platform applications
The techniques shown here work consistently from Vista through Windows 11, though later versions may add additional constraints in certain scenarios.