I use this batch script written by Mofi to move folders into other folders.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
%SystemRoot%\System32\tree.com
for /F "eol=| delims=" %%I in ('dir /AD /B 2^>nul') do (
set "FolderName=%%I"
setlocal EnableDelayedExpansion
set "TargetFolder=!FolderName:~0,1!"
if not "!TargetFolder!" == "!FolderName!" (
md "!TargetFolder!" 2>nul
move /-Y "!FolderName!" "!TargetFolder!\"
)
endlocal
)
%SystemRoot%\System32\tree.com
endlocal
It moves folders with two or more characters in current folder into a subfolder with name being the first character of the folder to move with automatic creation of the destination folder if not existing already.
But the batch script doesn't work if a folder name contains one or more Unicode characters.
Is there a workaround with PowerShell?
For example, it doesn't move a folder with first character being Ш
(Cyrillic capital letter SHA) into a folder with name Ш
.