Script says file does not exist when trying to remove illegal characters from file name but the file really does exist... RRS feed

  • Question

  • Hi,

    I am using this script to prep files prior to uploading to sharepoint: https://gallery.technet.microsoft.com/Check-for-unsupported-6676929a

    The script is great at detecting files that have illegal characters in such as # % & etc.

    It sucks at fixing the file names.

    The powershell window tells me that the file does not exist - but it does - i assure you 100% it does exist - i can see it in file explorer.

    If i copy these files to a folder and run the script against the folder it will remove the illegal characters.

    This is not practical to do for my data set that is millions of documents in hundreds of thousands of folders - all of which need to be run thru a simple script to remove illegal characters.

    I have tried 4 scripts now and they all fail in this way implying im doing something wrong - i have no idea what i might be doing wrong...please help - this is starting to drive me nuts now...


    • Edited by xyz2012 Friday, March 1, 2019 4:03 PM
    Friday, March 1, 2019 4:03 PM

All replies

  • For issues or question about gallery scripts you should contact the author in the Q & A section


    Live long and prosper!


    Friday, March 1, 2019 4:10 PM
  • Does this work (characters unsupported by Sharepoint/OneDrive)?

    get-childitem -recurse | where-object name -match '!|&|{|}|~|#|%' |
      Rename-item -NewName { $_ -replace '!|&|{|}|~|#|%' } -whatif

    Saturday, March 2, 2019 3:39 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Monday, March 4, 2019 7:04 AM
  • I haven't looked at the script you mentioned yet, but I only know of two cases where a program claims a file does not exist:

    - You have no permission to access that folder/share (In case of a share you can still access it from the full folder path that starts with the drive letter if you are an admin)

    - The file was originally added via share but attempting to access it from drive letter exceeds the MAX_PATH length. (In which case the simpler solution is to access the file via share, or alternatively -didn't test it myself yet- access the file remotely from a Windows 10/2016 machine that has been updated to use the newer MAX_PATH. The more complicated solution is to program your own solution that uses p/invoke to access the files via APIs that use the newer MAX_PATH)

    Tuesday, March 5, 2019 6:24 AM