最近因为重做系统,很多文件习惯的想放到机械硬盘里,默认对固态硬盘不信任,但不想每次都手动去变更,用批处理感觉最容易实现的,不用任何其他编程软件支持,打开即可使用,p1是原来的位置,p2是目标位置,p3备份文件位置,n是对应文件夹。
注意:由于有删除文件夹操作,所以使用务必谨慎。
20221129 稍微修改一下,感觉之前还是草率了,考虑不是很周到,二级目录不需要重新mklink,所以修正一下,本人水平比较有限,有什么错误的地方还请大神高抬贵手,帮忙指出。
Set p1=C:\Users\Administrator
Set p2=D:\Users\Administrator
Set p3=D:\Backups\Administrator
Set n1=Videos
Set n2=Favorites
Set n3=Favorites\Links
Set n4=Pictures
Set n5=Pictures\Saved Pictures
Set n6=Pictures\Camera Roll
Set n7=Documents
Set n8=Downloads
Set n9=Music
Set n10=Desktop
Set n11=Saved Games
Set f1=desktop.ini
Call:BkDir %n1%
Call:BkDir %n2%
Call:BkDir3 %n3%
Call:BkDir %n4%
Call:BkDir4 %n5%
Call:BkDir4 %n6%
Call:BkDir %n7%
Call:BkDir %n8%
Call:BkDir %n9%
Call:BkDir %n10%
Call:BkDir2 %n11%
if exist "%p2%\%n1%\%f1%" (attrib -H -S -A "%p2%\%n1%\%f1%")
>"%p2%\%n1%\%f1%" echo=
>>"%p2%\%n1%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n1%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21791
>>"%p2%\%n1%\%f1%" echo InfoTip=@C:\Windows\system32\shell32.dll,-12690
>>"%p2%\%n1%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-189
>>"%p2%\%n1%\%f1%" echo IconFile=C:\Windows\system32\shell32.dll
>>"%p2%\%n1%\%f1%" echo IconIndex=-238
attrib +H +S +A "%p2%\%n1%\%f1%"
if exist "%p2%\%n2%\%f1%" (attrib -H -S -A "%p2%\%n2%\%f1%")
>"%p2%\%n2%\%f1%" echo=
>>"%p2%\%n2%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n2%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21796
>>"%p2%\%n2%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-115
>>"%p2%\%n2%\%f1%" echo IconFile=C:\Windows\system32\shell32.dll
>>"%p2%\%n2%\%f1%" echo IconIndex=-173
attrib +H +S +A "%p2%\%n2%\%f1%"
if exist "%p2%\%n3%\%f1%" (attrib -H -S -A "%p2%\%n3%\%f1%")
>"%p2%\%n3%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n3%\%f1%" echo LocalizedResourceName=@C:\Windows\System32\ieframe.dll,-12385
attrib +H +S +A "%p2%\%n3%\%f1%"
if exist "%p2%\%n4%\%f1%" (attrib -H -S -A "%p2%\%n4%\%f1%")
>"%p2%\%n4%\%f1%" echo=
>>"%p2%\%n4%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n4%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21779
>>"%p2%\%n4%\%f1%" echo InfoTip=@C:\Windows\system32\shell32.dll,-12688
>>"%p2%\%n4%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-113
>>"%p2%\%n4%\%f1%" echo IconFile=C:\Windows\system32\shell32.dll
>>"%p2%\%n4%\%f1%" echo IconIndex=-236
attrib +H +S +A "%p2%\%n4%\%f1%"
if exist "%p2%\%n5%\%f1%" (attrib -H -S -A "%p2%\%n5%\%f1%")
>"%p2%\%n5%\%f1%" echo=
>>"%p2%\%n5%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n5%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\windows.storage.dll,-34583
attrib +H +S +A "%p2%\%n5%\%f1%"
if exist "%p2%\%n6%\%f1%" (attrib -H -S -A "%p2%\%n6%\%f1%")
>"%p2%\%n6%\%f1%" echo=
>>"%p2%\%n6%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n6%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\windows.storage.dll,-21824
attrib +H +S +A "%p2%\%n6%\%f1%"
if exist "%p2%\%n7%\%f1%" (attrib -H -S -A "%p2%\%n7%\%f1%")
>"%p2%\%n7%\%f1%" echo=
>>"%p2%\%n7%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n7%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21770
>>"%p2%\%n7%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-112
>>"%p2%\%n7%\%f1%" echo IconFile=C:\Windows\system32\shell32.dll
>>"%p2%\%n7%\%f1%" echo IconIndex=-235
attrib +H +S +A "%p2%\%n7%\%f1%"
if exist "%p2%\%n8%\%f1%" (attrib -H -S -A "%p2%\%n8%\%f1%")
>"%p2%\%n8%\%f1%" echo=
>>"%p2%\%n8%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n8%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21798
>>"%p2%\%n8%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-184
attrib +H +S +A "%p2%\%n8%\%f1%"
if exist "%p2%\%n9%\%f1%" (attrib -H -S -A "%p2%\%n9%\%f1%")
>"%p2%\%n9%\%f1%" echo=
>>"%p2%\%n9%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n9%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21790
>>"%p2%\%n9%\%f1%" echo InfoTip=@C:\Windows\system32\shell32.dll,-12689
>>"%p2%\%n9%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-108
>>"%p2%\%n9%\%f1%" echo IconFile=C:\Windows\system32\shell32.dll
>>"%p2%\%n9%\%f1%" echo IconIndex=-237
attrib +H +S +A "%p2%\%n9%\%f1%"
if exist "%p2%\%n10%\%f1%" (attrib -H -S -A "%p2%\%n10%\%f1%")
>"%p2%\%n10%\%f1%" echo=
>>"%p2%\%n10%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n10%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21769
>>"%p2%\%n10%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-183
attrib +H +S +A "%p2%\%n10%\%f1%"
if exist "%p2%\%n11%\%f1%" (attrib -H -S -A "%p2%\%n11%\%f1%")
>"%p2%\%n11%\%f1%" echo=
>>"%p2%\%n11%\%f1%" echo [.ShellClassInfo]
>>"%p2%\%n11%\%f1%" echo LocalizedResourceName=@C:\Windows\system32\shell32.dll,-21814
>>"%p2%\%n11%\%f1%" echo IconResource=C:\Windows\system32\imageres.dll,-186
attrib +H +S +A "%p2%\%n11%\%f1%"
exit
:BkDir
if not exist "%p3%\%1" (md "%p3%\%1")
for /f "tokens=3 delims= " %%i in ('dir "%p1%" |findstr %1') do (
if %%i==^<DIR^> (
robocopy /e "%p1%\%1" "%p3%\%1"
rd /s /q "%p1%\%1"
)
)
if not exist "%p2%\%1" (md "%p2%\%1")
attrib /D +R "%p2%\%1"
if not exist "%p1%\%1" (mklink /J "%p1%\%1" "%p2%\%1")
goto:eof
:BkDir2
if not exist "%p3%\%1 %2" (md "%p3%\%1 %2")
for /f "tokens=3 delims= " %%i in ('dir "%p1%" |findstr %1') do (
if %%i==^<DIR^> (
robocopy /e "%p1%\%1 %2" "%p3%\%1 %2"
rd /s /q "%p1%\%1 %2"
)
)
if not exist "%p2%\%1 %2" (md "%p2%\%1 %2")
attrib /D +R "%p2%\%1 %2"
if not exist "%p1%\%1 %2" (mklink /J "%p1%\%1 %2" "%p2%\%1 %2")
goto:eof
:BkDir3
if not exist "%p2%\%1" (md "%p2%\%1")
attrib /D +R "%p2%\%1"
goto:eof
:BkDir4
if not exist "%p2%\%1 %2" (md "%p2%\%1 %2")
attrib /D +R "%p2%\%1 %2"
goto:eof