|
本帖最后由 wxinchun92 于 2024-3-23 15:03 编辑
原帖批处理迁移系统用户文件夹位置 - 综合讨论区 - 无忧启动论坛 - Powered by Discuz! (wuyou.net)
适用于win7及以上
纠正部分路径错误
增加自动运行
- @echo off
- title 移动目标文件夹位置向导 by chishingchan
- SETLOCAL ENABLEDELAYEDEXPANSION
- set drive=.
- set choice=.
- set Name=
- for /f "tokens=6 delims=[]. " %%i in ('ver') do set winbuild=%%i
- if %winbuild% LSS 7600 mshta vbscript:CreateObject("Wscript.Shell").popup("仅支持 Windows 7及以上的系统运行!",5,"提示",64)(window.close)&&exit
- set _NCS=1
- if %winbuild% GEQ 10586 reg query "HKCU\Console" /v ForceV2 %nul2% | find /i "0x0" %nul1% && (set _NCS=0)
- if %_NCS% EQU 1 call :_colorprep
- if "%1"=="/?" goto help
- if /i "%1"=="/h" goto help
- if %winbuild% GEQ 16299 set doj=1
- set regg=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer
- set "_work=%~dp0"
- if "%_work:~-1%"=="" set "_work=%_work:~0,-1%"
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "Desktop"') do set Current_Desktop=%%b
- if %Current_Desktop% EQU %_work% mshta vbscript:CreateObject("Wscript.Shell").popup("请勿在桌面运行此脚本!",5,"提示",64)(window.close)&&exit
- for /f "tokens=3" %%i in ('wmic logicaldisk where DriveType^=3 Get FileSystem^,FreeSpace^,Name^,Size^|findstr ":"') do if not %%i==%SystemDrive% set Name=%%i !Name!
- set choice=!Name!
- for %%i in (%choice%) do if exist %%i\nul if not exist "%%i\Windows\explorer.exe" set drive=%%i
- if "%drive%"=="." mshta vbscript:CreateObject("Wscript.Shell").popup("没有发现可用驱动器!",4,"错误",64)(window.close)&&exit
- set CopyFile=N
- set DelFile=N
- if "%2" NEQ "" call :config %2
- set HP=\Users\%USERNAME%
- if /i "%1"=="/u" goto default
- echo 正在检测系统,请稍候...
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}"') do set Current_Saved_Games=%%b
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "{56784854-C6CB-462B-8169-88E350ACB882}"') do set Current_Contacts=%%b
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}"') do set Current_Links=%%b
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}"') do set Current_Searches=%%b
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "Favorites"') do set Current_Favorites=%%b
- for /f "tokens=3*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "My Video"') do set Current_My_Video=%%b
- for /f "tokens=3*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "My Pictures"') do set Current_My_Pictures=%%b
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "Personal"') do set Current_Personal=%%b
- for /f "tokens=3*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "My Music"') do set Current_My_Music=%%b
- for /f "tokens=2*" %%a in ('REG QUERY "%regg%\Shell Folders" /v "{374DE290-123F-4565-9164-39C4925E467B}"') do set Current_Downloads=%%b
- if defined doj (
- for /f "skip=2 tokens=2*" %%a in ('REG QUERY "%regg%\User Shell Folders" /v "{31C0DD25-9439-4F12-BF41-7FF4EDA38722}"') do set Current_Objects=%%b
- )
- if "%1" EQU "" goto input
- set conf=%1
- call :cap %conf% conf
- echo %choice%|findstr /ic "%conf%">nul 2>nul
- if %errorlevel% NEQ 0 mshta vbscript:CreateObject("Wscript.Shell").popup("驱动器不存在!",3,"错误",64)(window.close)&&exit
- set Drive_Letter=%conf%
- set REG_EX=%Drive_Letter%%HP%
- goto auto
- :input
- cls
- echo %Def%当前文件夹位置:
- echo.
- echo.『我的文档』 %_dBlue%%Current_Personal%%Def%
- echo.『桌面』 %_dBlue%%Current_Desktop%%Def%
- echo.『下载』 %_dBlue%%Current_Downloads%%Def%
- echo.『收藏夹』 %_dBlue%%Current_Favorites%%Def%
- echo.『我的图片』 %_dBlue%%Current_My_Pictures%%Def%
- echo.『我的视频』 %_dBlue%%Current_My_Video%%Def%
- echo.『我的音乐』 %_dBlue%%Current_My_Music%%Def%
- echo.『保存的游戏』 %_dBlue%%Current_Saved_Games%%Def%
- echo.『联系人』 %_dBlue%%Current_Contacts%%Def%
- echo.『链接』 %_dBlue%%Current_Links%%Def%
- echo.『搜索』 %_dBlue%%Current_Searches%%Def%
- if defined doj (echo.『3D 对象』 %_dBlue%%Current_Objects%%Def%)
- echo.%_Green%
- echo. U 还原默认
- echo. Q 退出
- echo.%_Yellow%
- set Drive_Letter=%drive%
- set /P Drive_Letter="请输入目标驱动器(默认值:%drive%) [%choice%] "
- echo.
- if /i "%Drive_Letter%"=="Q" goto end
- if /i "%Drive_Letter%"=="U" goto copyfiles
- call :cap %Drive_Letter% Drive_Letter
- if "%Drive_Letter%"=="%drive%" goto copyfiles
- mshta vbscript:CreateObject("Wscript.Shell").popup("输入有误,未找到对应驱动器!",2,"错误",64)(window.close)
- goto input
- :copyfiles
- set /P CopyFile="是否复制文件夹到驱动器(默认值:N) [ 返回(R) | 是(Y) | 否(N) ] "
- echo.
- if /i "%CopyFile%"=="Y" goto delsource
- if /i "%CopyFile%"=="N" goto delsource
- if /i "%CopyFile%"=="R" goto input
- set CopyFile=N
- mshta vbscript:CreateObject("Wscript.Shell").popup("输入有误!",2,"错误",64)(window.close)
- goto copyfiles
- :delsource
- set /P DelFile="是否删除源驱动器文件夹(默认值:N) [ 返回(R) | 是(Y) | 否(N) ] "
- echo.
- if /i "%DelFile%"=="Y" goto info
- if /i "%DelFile%"=="N" goto info
- if /i "%DelFile%"=="R" goto input
- set DelFile=N
- mshta vbscript:CreateObject("Wscript.Shell").popup("输入有误!",2,"错误",64)(window.close)
- goto delsource
- :info
- if /i "%CopyFile%"=="N" set CopyFilee=%_Blue%不%Def%
- if /i "%CopyFile%"=="Y" set CopyFilee=%_Red%是%Def%
- if /i "%DelFile%"=="N" set DelFilee=%_Blue%不%Def%
- if /i "%DelFile%"=="Y" set DelFilee=%_Red%是%Def%
- if /i "%Drive_Letter%"=="U" goto default
- set REG_EX=%Drive_Letter%%HP%
- goto connf
- :default
- set Drive_Letter=%HOMEDRIVE%
- set REG_EX=%%USERPROFILE%%
- if "%1" NEQ "" goto auto
- :connf
- echo %Def%================================= 配 置 信 息 =================================
- echo 目标驱动器:%_Red%%Drive_Letter%%HP%%Def%
- echo 复制文件夹:%CopyFilee%
- echo 删除源文件:%DelFilee%
- echo ===============================================================================
- echo.&&pause&&echo.
- :auto
- set shel=shell32.dll
- if "%Current_Desktop:~0,1%"=="%Drive_Letter:~0,1%" mshta vbscript:CreateObject("Wscript.Shell").popup("目标驱动器与当前驱动器相同!",2,"错误",64)(window.close)&&exit
- echo %_lBlue%正在处理『我的文档』...
- set Icon=-21770
- set Icon1=-112
- set Icon2=-235
- call :aing "%Current_Personal%" Documents Personal "{F42EE2D3-909F-4907-8871-4C22FC0BF756}"
- echo 正在处理『桌面』...
- set Icon=-21769
- set Icon1=-183
- call :aing "%Current_Desktop%" Desktop Desktop "{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}"
- echo 正在处理『下载』...
- set Icon=-21798
- set Icon1=-184
- call :aing "%Current_Downloads%" Downloads "{374DE290-123F-4565-9164-39C4925E467B}" "{7D83EE9B-2244-4E70-B1F5-5393042AF1E4}"
- echo 正在处理『收藏夹』...
- set Icon=-21796
- set Icon1=-115
- set Icon2=-173
- call :aing "%Current_Favorites%" Favorites Favorites
- echo 正在处理『我的图片』...
- set Icon=-21779
- set Icon1=-113
- set Icon2=-236
- set Icon3=-12688
- call :aing "%Current_My_Pictures%" Pictures "My Pictures" "{0DDD015D-B06C-45D5-8C4C-F59713854639}"
- echo 正在处理『我的视频』...
- set Icon=-21791
- set Icon1=-189
- set Icon2=-238
- set Icon3=-12690
- call :aing "%Current_My_Video%" Videos "My Video" "{35286A68-3C57-41A1-BBB1-0EAE73D76C95}"
- echo 正在处理『我的音乐』...
- set Icon=-21790
- set Icon1=-108
- set Icon2=-237
- set Icon3=-12689
- call :aing "%Current_My_Music%" Music "My Music" "{A0C69A99-21C8-4671-8703-7934162FCF1D}"
- echo 正在处理『保存的游戏』...
- set Icon=-21814
- set Icon1=-186
- call :aing "%Current_Saved_Games%" "Saved Games" "{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}"
- echo 正在处理『联系人』...
- set Icon=-10100
- set Icon1=-181
- set Icon3=-10200
- call :aing "%Current_Contacts%" Contacts "{56784854-C6CB-462B-8169-88E350ACB882}"
- echo 正在处理『链接』...
- set Icon=-21810
- set Icon1=-185
- call :aing "%Current_Links%" Links "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}"
- echo 正在处理『搜索』...
- set Icon=-9031
- set Icon1=-18
- call :aing "%Current_Searches%" Searches "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}"
- if not defined doj goto icoo
- echo %_lBlue%正在处理『3D 对象』...
- set shel=windows.storage.dll
- set Icon=-21825
- set Icon1=-198
- call :aing "%Current_Objects%" "3D Objects" "{31C0DD25-9439-4F12-BF41-7FF4EDA38722}"
- :icoo
- rem 正在处理『图标缓存』...
- attrib -r -a -s -h "%USERPROFILE%\AppData\Local\IconCache.db">nul 2>nul
- del /f /q "%USERPROFILE%\AppData\Local\IconCache.db">nul 2>nul
- goto end
- :aing
- md %Drive_Letter%%HP%\%2
- if /i %CopyFile% EQU Y xcopy %~1\*.* %Drive_Letter%%HP%\%2\ /s /y>nul 2>nul
- attrib -r -a -s -h %Drive_Letter%%HP%\%2\desktop.ini>nul 2>nul
- echo.>%Drive_Letter%%HP%\%2\desktop.ini
- echo [.ShellClassInfo]>>%Drive_Letter%%HP%\%2\desktop.ini
- echo LocalizedResourceName=@%%SystemRoot%%\system32\%shel%,%Icon%>>%Drive_Letter%%HP%\%2\desktop.ini
- if defined Icon3 echo InfoTip=@%%SystemRoot%%\system32\shell32.dll,%Icon3%>>%Drive_Letter%%HP%\%2\desktop.ini
- echo IconResource=%%SystemRoot%%\system32\imageres.dll,%Icon1%>>%Drive_Letter%%HP%\%2\desktop.ini
- if defined Icon2 echo IconFile=%%SystemRoot%%\system32\shell32.dll>>%Drive_Letter%%HP%\%2\desktop.ini
- if defined Icon2 echo IconIndex=%Icon2%>>%Drive_Letter%%HP%\%2\desktop.ini
- if %2==Links call :lnk
- if %2==Searches call :srs
- attrib -r +a +s +h %Drive_Letter%%HP%\%2\desktop.ini>nul 2>nul
- attrib -r +a +s -h %Drive_Letter%%HP%\%2 /s /d>nul 2>nul
- reg add "%regg%\Shell Folders" /f /v %3 /t REG_SZ /d "%Drive_Letter%%HP%\%~2">nul 2>nul
- reg add "%regg%\User Shell Folders" /f /v %3 /t REG_EXPAND_SZ /d "%REG_EX%\%~2">nul 2>nul
- set usf=%4
- if defined usf reg add "%regg%\User Shell Folders" /f /v %4 /t REG_EXPAND_SZ /d "%REG_EX%\%~2">nul 2>nul
- if /i %DelFile% EQU Y rd /s /q %1>nul 2>nul
- set usf=
- set Icon=
- set Icon1=
- set Icon2=
- set Icon3=
- exit /b
- :config
- set con=%1
- echo %con%|findstr /i "c">nul && set "CopyFile=Y"
- echo %con%|findstr /i "d">nul && set "DelFile=Y"
- exit /b
- ::字体颜色
- :_colorprep
- for /f %%a in ('echo prompt $E ^| cmd') do set "esc=%%a"
- set "Def=%esc%[0m"
- set "_Red=%esc%[;91m"
- set "_Green=%esc%[;92m"
- set "_Blue=%esc%[;94m"
- set "_dBlue=%esc%[;96m"
- set "_lBlue=%esc%[;36m"
- set "_Yellow=%esc%[;93m"
- exit /b
- :help
- echo.
- echo. %_Yellow%%~nx0%Def% [drive:] [/U] [/H] [/CD]
- echo.
- echo. drive: 目标驱动器,可以不加冒号:
- echo. /U 还原默认
- echo. /H 帮助
- echo. /CD C-复制文件夹,D-删除源文件,可单独使用,默认不复制不删除
- echo.
- echo.eg. %_lBlue%%~nx0 d /cd%Def% 移动到D盘
- echo. %_lBlue%%~nx0 e%Def% 在E盘新建一个用户文件夹
- echo.
- echo. 直接运行 %_Yellow%%~nx0%Def% 启动向导。
- echo.
- goto :EOF
- ::添加冒号&转大写
- :cap
- set aa=%~1
- if "%aa:~-1%" NEQ ":" (set "aa=%aa%:")
- for /f "delims=" %%a in ('tree "\$\%aa%"^|find /i ":\$\%aa%"') do set aa=%%~nxa
- set "%~2=%aa%"
- exit /b
- :lnk
- echo DefaultDropEffect=^4>>%Drive_Letter%%HP%\Links\desktop.ini
- echo [LocalizedFileNames]>>%Drive_Letter%%HP%\Links\desktop.ini
- echo RecentPlaces.lnk=@shell32.dll,-37217>>%Drive_Letter%%HP%\Links\desktop.ini
- echo Desktop.lnk=@shell32.dll,-21769>>%Drive_Letter%%HP%\Links\desktop.ini
- echo Downloads.lnk=@shell32.dll,-21798>>%Drive_Letter%%HP%\Links\desktop.ini
- exit /b
- :srs
- echo [LocalizedFileNames]>>%Drive_Letter%%HP%\Searches\desktop.ini
- echo Indexed Locations.search-ms=@searchfolder.dll,-32820>>%Drive_Letter%%HP%\Searches\desktop.ini
- echo Everywhere.search-ms=@searchfolder.dll,-32822>>%Drive_Letter%%HP%\Searches\desktop.ini
- exit /b
- :end
- taskkill /f /im explorer.exe
- start explorer.exe
- exit
复制代码
|
-
-
win.txt
21.42 KB, 下载次数: 13, 下载积分: 无忧币 -2
-
-
win1.txt
10.98 KB, 下载次数: 10, 下载积分: 无忧币 -2
评分
-
查看全部评分
|