How to Remove Special Characters from Folder Names in Windows 10

Abstract: Resolve Windows 10 folder name errors caused by invalid characters like colons and asterisks using a PowerShell script to safely replace them with underscores.

Created: 2026-10-09 by

Remove special characters from folder names in Windows 10 by using PowerShell to identify invalid path characters and replace them with underscores. This approach ensures compatibility with file system constraints, prevents errors during synchronization, and maintains a clean directory structure without relying on manual renaming.

Understanding Invalid File System Characters

Windows imposes strict rules on what characters can exist within a file or folder name. These restrictions are inherited from the underlying NTFS file system and older DOS conventions that still influence modern Windows behavior. When you attempt to create a folder containing certain symbols, the operating system blocks the action to prevent ambiguity in path parsing. The most common invalid characters include:
  • < (Less than)
  • > (Greater than)
  • : (Colon)
  • * (Asterisk)
  • ? (Question mark)
  • " (Double quote)
  • / (Forward slash)
  • \ (Backslash)
  • | (Pipe)
Additionally, names cannot end with a space or a period, although this is less of an issue for simple character removal. If your folders contain these symbols, tools like OneDrive, robocopy, or even basic Explorer operations may fail. Understanding these limitations is the first step toward automating their removal. For more context on managing file paths programmatically, see How to Set the Target of a .lnk File Programmatically with PowerShell or C++.

Preparation and Safety Checks

Before running any script that modifies filenames, it is crucial to ensure you do not accidentally overwrite existing data. PowerShell provides powerful string manipulation capabilities, but they are destructive if not handled carefully. Always test your logic on a small subset of files before applying it to entire directories. Start by opening PowerShell as an administrator. While renaming user folders often does not require elevated privileges, accessing system directories or handling permission issues might. You can open the Start menu, type "PowerShell", right-click the result, and select "Run as administrator". Create a backup or simply review the list of affected folders first. Use the following command to preview which folders contain invalid characters without making changes:
$invalidChars = '<>:*?"|\'
$folders = Get-ChildItem -Path 'C:\Your\Target\Folder' -Directory

foreach ($folder in $folders) {
    if ($folder.Name -match '[<>:*?"|\\]') {
        Write-Host "Found invalid char in: $($folder.FullName)"
    }
}
This script iterates through all subdirectories in the specified path. It uses a regular expression to check if the name contains any of the forbidden symbols. If found, it prints the full path to the console. Verify that these are indeed the folders you intend to clean.

Automating the Renaming Process

Once you have verified the target folders, you can proceed with the actual renaming operation. The goal is to replace each invalid character with a safe alternative, such as an underscore (_) or a hyphen (-). Underscores are generally preferred because they preserve readability better than hyphens in complex names. Use the following script to perform the replacement. This example replaces all invalid characters with underscores:
$invalidChars = '<>:*?"|\'
$targetPath = 'C:\Your\Target\Folder'

Get-ChildItem -Path $targetPath -Directory | ForEach-Object {
    $oldName = $_.Name
    $newName = $oldName -replace '[<>:*?"|\\]', '_'
    
    if ($oldName -ne $newName) {
        try {
            Rename-Item -Path $_.FullName -NewName $newName -ErrorAction Stop
            Write-Host "Renamed: $oldName -> $newName"
        } catch {
            Write-Warning "Failed to rename $oldName : $_"
        }
    }
}
The -replace operator in PowerShell accepts regular expressions. By wrapping the invalid characters in square brackets, we tell PowerShell to match any single occurrence of those symbols. The script checks if the new name differs from the old one to avoid unnecessary operations. The try-catch block handles potential errors, such as if another process has locked the folder or if the new name already exists. For deeper insights into troubleshooting command-line issues that might arise during batch operations, refer to Troubleshooting Windows: How to Fix Hard Drive Issues Using Command Line.

Handling Edge Cases

Sometimes, folders may have trailing spaces or periods, which are also technically invalid in many contexts, though Windows Explorer sometimes hides this error. To address this, extend your regex or add a trimming step:
$newName = $newName.TrimEnd('. ', '_')
This ensures that any accidental whitespace or dots at the end of the name are cleaned up. Be cautious when combining multiple replacements, as order matters. For instance, replacing backslashes first might break the path if not done correctly within the filename context only. Since we are only modifying the Name property and not the FullName, path separators inside the name itself are rare but possible if created via legacy APIs.

Verification and Cleanup

After running the script, verify the results by browsing to the target directory. Check a few randomly selected folders to ensure the names look correct and no data was lost. If you notice unexpected naming patterns, you can reverse the process by manually renaming or writing a reverse script. It is also advisable to update any shortcuts or symbolic links that pointed to the old names. Shortcuts do not automatically update when you rename the target folder. You may need to recreate them or use a tool to update the target path. If you encounter issues where folders cannot be renamed due to permissions, ensure you are running the script with appropriate privileges. In some cases, taking ownership of the folder may be necessary, which involves using the Takeown command or adjusting Security properties in the GUI.

Frequently Asked Questions

Can I use Command Prompt instead of PowerShell?

Yes, but it is significantly more difficult. Batch scripting lacks native regular expression support, making it hard to handle multiple special characters efficiently. You would need to write a complex loop with multiple ren commands, which is prone to syntax errors. PowerShell is the recommended tool for this task.

Will removing special characters delete my files?

No, renaming a folder only changes its label in the file system index. The contents of the folder remain intact and accessible after the rename. However, always backup important data before performing bulk operations to protect against unexpected script errors.

What happens if two folders have the same new name?

The Rename-Item cmdlet will throw an error if the destination name already exists. Our script includes a try-catch block to capture this error and print a warning. It will skip the conflicting folder, allowing the rest of the batch to complete successfully.

Does this work for hidden system folders?

By default, Get-ChildItem does not return hidden items. Add the -Force parameter to include hidden folders in the scan. Be extremely careful when renaming system folders, as it may break applications or Windows functionality. Stick to user-created directories whenever possible.

How do I restore original names if something goes wrong?

PowerShell does not keep a history of previous names. You must rely on backups or version control systems like File History. If you did not take a backup, you may need to manually reconstruct the names based on memory or external documentation, which is why testing on a small subset first is critical.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More