Folders with trailing blanks

SoporteSW 1 Reputation point
2022-06-06T23:32:10.59+00:00

Hello, I have the following situation

With the start of the pandemic I had to create a cloud server using Owncloud to get by, the shared units that we use in the office were mounted on said cloud and from there the users worked for a while. Today that we are back to work locally we found problems with some folders, not all of them, that when manipulated they are duplicated and then the content inside is not shown and the security tab does not show anything, I was able to detect that this surely happened because from Owncloud folders were created with blank spaces at the end (which it allowed because its base system is linux), but this is a problem from Windows, the solution was to rename the folders by exploring the directory with 7zip to remove the blank space and then everything goes back to normal.

The issue is that I only notice when the user encounters this problem, my question would be if there is a way to locate those folders that have a space at the end in the entire directory to be able to preventively correct this?

Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-06-07T00:14:13.933+00:00

    Try this Powershell script.

    $folder = '\\?\c:\temp'     #  Note, requires Powershell.exe, it will not work in Powershell_ise. 
    
    Get-ChildItem -path $folder -Recurse -Directory | foreach {
        if ($_.Name.EndsWith(' ')) {
            $_.FullName
            $_ | Rename-Item -NewName $_.Name.Trim()  -whatif      # remove whatif to actually do the rename. 
        }
    }
    

    Run it once to find a spaced folder. Then point $folder to that folder and remove the -whatif. Test the rename on the one folder before updating the entire folder structure.

    1 person found this answer helpful.

  2. SoporteSW 1 Reputation point
    2022-06-07T00:31:19.877+00:00

    Thanks for the reply, I'm not that experienced with powershell but I'm going to try this on a bkp drive from a few months ago to see if it works.

    0 comments No comments

  3. SoporteSW 1 Reputation point
    2022-06-07T00:55:50.367+00:00

    sorry, one question. I have to execute the script from the general container? example D:\DOCS?


  4. Limitless Technology 39,916 Reputation points
    2022-06-07T15:01:04.083+00:00

    Hello,

    here is a very well explained guide from the Microsoft Devblogs.

    How Can I Remove Blank Spaces From File Names?
    https://devblogs.microsoft.com/scripting/how-can-i-remove-blank-spaces-from-file-names/


    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  5. SoporteSW 1 Reputation point
    2022-07-12T15:50:12.387+00:00

    thanks to all, finally I used robocopy to make a copy and using the log options I was able to list the folders and search right there and find them, it is much more precarious but it was effective for my level of knowledge.
    Thanks again everyone.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.