Link to home
Start Free TrialLog in
Avatar of Broadsound
Broadsound

asked on

Fastest way to search a directory for file names with specific characters

We just started using Office365 and, unbeknownst to us, you can't upload files containing certain characters to Sharepoint Online. The names of the files we are trying to upload cannot contain these characters:   " # % & * : < > ? \ / { | } ~
We have all of the folders that we plan on uploading in a single directory called "to be uploaded to sharepoint"
Is there any way to search through this directory and all of the subfolders in that directory for files with those invalid characters in their names?
I tried using a command like this,

dir *#* *%* *^&* *{* *}* *~*  /s /b > bad_file_names.txt

that I found on another website, but it just returns a list of all of the files and folders in that directory, regardless of whether or not their name contains an invalid character.

Any advice would be greatly appreciated.
Avatar of footech
footech
Flag of United States of America image

Some of those characters aren't valid for NTFS, so it does no good to search for them.  Here's a line of PowerShell code that should work for you.
Get-ChildItem "c:\tobeuploadedtosharepoint" -recurse | Where { $_.name -match "[#%&{}~]" } | Select FullName

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Broadsound
Broadsound

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Broadsound--
Put the files into a Folder, do not use any of the forbidden characters as the Folder's Name.  Upload.
Avatar of Broadsound
Broadsound

ASKER

Found an application online that does exactly what I need