Drilling into a drive and changing folder names & document names
I have a drive on my computer that has folder--some of which have lots of folders w/in other folders and also contain files.
I need to migrate these docs into sharepoint, however a LOT of these folders and files have invalid characters that will not allow me to migrate into sharepoint (i.e. " / \ &, etc.)Is there any way to write something in C# that basically removes these invalid characters from all folders and files?
Please he开发者_如何学运维lp!
Yes. A way to do this would be to drill through the directory structure recursively, and for each file name, check if it is valid, and if it is not valid, make a valid filename, and upload to Sharepoint.
You can make a Regex that matches all disallowed characters, and replace them with an allowed character, such as underscore. If you need names to be unique, and you are worried you might create duplicate names with this approach, store all names that has been used (ie. uploaded to Sharepoint) in something like a HashSet, and check that before using the generated name. If the name already exists, you can add a pre- or suffix, flag for human intervention, or do something else, depending on your requirements.
精彩评论