Avatar of LightWire
LightWire
 asked on

How to find or search for invalid characters for OneDrive upload

Looking how to find or search for the following invalid characters in all the shared folders to prepare to upload to OneDrive.  

The characters are:

\
/
:
*
?



|
#
%
Microsoft 365Microsoft Legacy OS

Avatar of undefined
Last Comment
Anand Shaw Shaw

8/22/2022 - Mon
arnold

What are you using to upload? a pattern match in your application to validate the file name .......
LightWire

ASKER
I need to verify my data structure before I proceed in the upload.  Is there a script I can use to produce an list of the output so it can be modified?
arnold

Yes.

Depending on what it is you are using, you have to look at the naming convention you use and make sure it matches the requirements .
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
LightWire

ASKER
I understand, but this is a customer's structure and they have over 100k + files/folders and I would like to search via a script instead of one at a time.
arnold

What scripting language are you using? powershell, vbscript, perl, batch, etc.
Each one has their own methods to traverse directories, and looking at filenames and then performing a pattern match to see whether they meet the requirements or have invalid characters.
 
You need to provide what options are available to you with which you are familiar at which point ....... it would be simpler to guide you along to the solution.
LightWire

ASKER
I'm not a script writer per say but can modify one when needed.  I am familiar with PS, VBS and batch
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
arnold

Here is an example of listing files in directories and sub folders.
vbscript example and powershell example.

http://blogs.technet.com/b/heyscriptingguy/archive/2014/02/03/list-files-in-folders-and-subfolders-with-powershell.aspx

Are you looking for someone to write you the script?
or are you looking for suggestions/correction of your own script that is doing somethings but not all that you need?

What is the end goal of your script processing?
Are you looking to rename the filenames to meet the parameters of onedrive?

An example of a powershell script that will replace "inavalid" characters with an alternate valid one.
http://pshscripts.blogspot.com/2013/11/fix-filenameps1.html

The general premise is
list the current directory, if it is a file, check the naming convention.
If it is a directory, check the naming convention and then look further within.

You can do it iteratively.
Function to look through the directory that is being passed to it. and if it hits a directory calls the same function with the new path as the argument
find_files (c:\)
find_files(c:\somedirectory)
etc.
ASKER CERTIFIED SOLUTION
David Johnson, CD

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
LightWire

ASKER
I seen a ps script like this one as well which I will run tomorrow. Thx
LightWire

ASKER
I've requested that this question be closed as follows:

Accepted answer: 0 points for lightwireinc's comment #a40686146

for the following reason:

Script runs good and helped find what I needed
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
arnold

I think you forgot to choose the comment with the script that helped you resolve the issue at hand. Your own comment acknowledges the assistance and is not a solution.
LightWire

ASKER
This script was very helpful and was what I was trying to use from another find but did not work properly.  I did modify the search by adding the following characters


            $illegalChars = '[&{}~#%/:*?<>|]'

#These characters may be used on the file system but not SharePoint
                if ($_.Value -match "&") { $newFileName = ($newFileName -replace "&", "and") }
                if ($_.Value -match "{") { $newFileName = ($newFileName -replace "{", "(") }
                if ($_.Value -match "}") { $newFileName = ($newFileName -replace "}", ")") }
                if ($_.Value -match "~") { $newFileName = ($newFileName -replace "~", "-") }
                if ($_.Value -match "#") { $newFileName = ($newFileName -replace "#", "") }
                if ($_.Value -match "%") { $newFileName = ($newFileName -replace "%", "") }
            if ($_.Value -match "/") { $newFileName = ($newFileName -replace "/", "") }
            if ($_.Value -match ":") { $newFileName = ($newFileName -replace ":", "") }
            if ($_.Value -match "'*") { $newFileName = ($newFileName -replace "'*", "") }
            if ($_.Value -match "'?") { $newFileName = ($newFileName -replace "'?", "") }
              if ($_.Value -match "<") { $newFileName = ($newFileName -replace "<", "") }
            if ($_.Value -match ">") { $newFileName = ($newFileName -replace ">", "") }
            if ($_.Value -match "|") { $newFileName = ($newFileName -replace "|", "") }
            }
LightWire

ASKER
Sorry arnold, I chose the wrong thing.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
howard brooks

The Long path tool is the very best program for error, unlock solution.and it is very useful tool.
Anand Shaw Shaw

“Long Path Tool” is very helpful for this error ! best solution for your problem.