我想移动大约 4,000 个文件夹,并将它们与具有相似名称的相应文件夹合并

我想移动大约 4,000 个文件夹,并将它们与具有相似名称的相应文件夹合并

我想移动大约 4,000 个文件夹,并将它们与具有相似名称的相应文件夹合并。文件夹名称示例:5 TAHOE VIEW COURT

合并: 5 Tahoe View Ct_Lot 文件

并且还有很多与此类似的地址文件夹。

我更喜欢批处理文件,但 PowerShell 命令也很好。

我努力了

@Echo off
pushd "C:\path\to\your\base\folder"
for /f "Tokens=1* Delims=-" %%A in (
  'Dir /B /AD *-*'
) Do If Not Exist "%%A" (
  Ren "%%A-%%B" "%%A"
) Else (
  Move /Y "%%A-%%B\*" "%%A\"
  RmDir "%%A-%%B"
)
PopD

@echo off
setlocal enabledelayedexpansion

:: Variables.

set "rootDir=C:\Users\T450s\Desktop\Merge\"
set "logName=RoboCopy.log"


:: Ensures %rootDir% value contains trailing slash.

if not [%rootDir:~1%] EQU [\] set "rootDir=%rootDir%\"


:: Jumps to the rootDir so that for loop will only display folder names and not the full path.

pushd %rootDir%


:: Loop through all folders located at %rootDir% and for each folder...
::    Use Robocopy.exe to MOVE(and delete original folder) contents of the folder to a new folder named with just first 7 characters of original folder, and delete the original folder.
::    Log the actions of RoboCopy to the screen and also a file called %logName% in the %rootDir% location.

for /d %%a in (*) do (
    set "currentDir=%%a"
    robocopy.exe "%rootDir%%%a" "%rootDir%!currentDir:~0,7!" /MOVE /E /R:3 /W:10 /V /LOG+:%rootDir%%logName% /FP /TEE /XC /XN /XO
)


popd
endlocal

echo.
echo The task has finished.
echo.
pause

:eof

相关内容