Windows用户目录迁移,库迁移,修复文件夹图标

用户目录迁移,库迁移

  每次重装系统都要备份桌面、文档、图片、音乐、视频、下载等,非常麻烦。思路就是把用户目录下的目录设置到其他盘的目录,以后重装系统再把目录设置到上一系统设置的位置,这样所有的文件都换在,更重要的是不会占用C盘的空间,可以说是一举两得。
  脚本在win10,win7上测试通过。
  脚本在哪运行,目录就会被迁移到哪,当然也可以自己定义路径,只需要修改下面变量的路径即可,%~dp0代表脚本所在目录,也可以修改成绝对路径。

set DocumentsDir=%~dp0Documents
set DesktopDir=%~dp0Desktop
set DownloadsDir=%~dp0Downloads
set FontsDir=%~dp0Fonts
set FavoritesDir=%~dp0Favorites
set PicturesDir=%~dp0Pictures
set VideosDir=%~dp0Videos
set MusicDir=%~dp0Music
set SavedGamesDir=%~dp0Saved Games
set ContactsDir=%~dp0Contacts
set LinksDir=%~dp0Links
set SearchesDir=%~dp0Searches

下面是批处理代码和copyx命令的代码:

copyx是AutoIt3编写的,用来调用系统自带的复制文件对话框的命令。运行脚本前请将此代码编译成copyx.exe并放在批处理的目录下即可,否则将不会复制文件,可能造成文件丢失。

@echo off
title 一键迁移库-作者:曹磊
set cd=%~dp0
rem set cd=%cd:~0,-1%
set DocumentsDir=%cd%Documents
set DesktopDir=%cd%Desktop
set DownloadsDir=%cd%Downloads
set FontsDir=%cd%Fonts
set FavoritesDir=%cd%Favorites
set PicturesDir=%cd%Pictures
set VideosDir=%cd%Videos
set MusicDir=%cd%Music
set SavedGamesDir=%cd%Saved Games
set ContactsDir=%cd%Contacts
set LinksDir=%cd%Links
set SearchesDir=%cd%Searches

set regPath1=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
set regPath2=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

echo 正在检测系统,请稍候...
call :CreateRedReg
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}"') do set Current_Saved_Games=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\{56784854-C6CB-462B-8169-88E350ACB882}"') do set Current_Contacts=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}"') do set Current_Links=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}"') do set Current_Searches=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\{374DE290-123F-4565-9164-39C4925E467B}"') do set Current_Downloads=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\Favorites"'                             ) do set Current_Favorites=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\My Video"'                              ) do set Current_My_Video=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\My Pictures"'                           ) do set Current_My_Pictures=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\Personal"'                              ) do set Current_Personal=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\My Music"'                              ) do set Current_My_Music=%%a
for /f "delims=" %%a in ('cscript //nologo "%cd%RedReg.vbs" "%regPath1%\Desktop"'                               ) do set Current_Desktop=%%a
del "%cd%RedReg.vbs"
cls
echo 当前目标文件夹位置:
echo.
echo 『文档』         %Current_Personal%      --^>      %DocumentsDir%
echo 『桌面』         %Current_Desktop%        --^>      %DesktopDir%
echo 『下载』         %Current_Downloads%      --^>      %DownloadsDir%
echo 『收藏夹』       %Current_Favorites%      --^>      %FavoritesDir%
echo 『图片』         %Current_My_Pictures%       --^>      %PicturesDir%
echo 『视频』         %Current_My_Video%         --^>      %VideosDir%
echo 『音乐』         %Current_My_Music%          --^>      %MusicDir%
echo 『保存的游戏』   %Current_Saved_Games%    --^>      %SavedGamesDir%
echo 『联系人』       %Current_Contacts%       --^>      %ContactsDir%
echo 『链接』         %Current_Links%          --^>      %LinksDir%
echo 『搜索』         %Current_Searches%       --^>      %SearchesDir%
echo.
set /p isCopy=是否复制原目录下的所有文件 Y [Y^|N]:
if not "%isCopy%"=="Y" if not "%isCopy%"=="N" if not "%isCopy%"=="y" if not "%isCopy%"=="n" set isCopy=Y
if "%isCopy%"=="y" set isCopy=Y
if "%isCopy%"=="n" set isCopy=N
set /p isDel=是否删除原来的目录 Y [Y^|N]:
if not "%isDel%"=="Y" if not "%isDel%"=="N" if not "%isDel%"=="y" if not "%isDel%"=="n" set isDel=Y
if "%isDel%"=="y" set isDel=Y
if "%isDel%"=="n" set isDel=N
echo.
echo 您的输入是:%isCopy% %isDel%
echo.
echo 按任意键开始迁移!
>nul 2>nul pause

::##########################『文档』##########################
echo 正在处理『文档』...
if not exist "%DocumentsDir%" md "%DocumentsDir%"
if "%isCopy%"=="Y" if not "%DocumentsDir%"=="%Current_Personal%" copyx "%Current_Personal%\*" "%DocumentsDir%"
>nul 2>nul call :PersonalIco %DocumentsDir%
>nul 2>nul attrib -r +a +s -h "%DocumentsDir%"
>nul 2>nul reg add "%regPath1%" /f /v "Personal" /t REG_SZ /d "%DocumentsDir%"
>nul 2>nul reg add "%regPath2%" /f /v "Personal" /t REG_EXPAND_SZ /d "%DocumentsDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{F42EE2D3-909F-4907-8871-4C22FC0BF756}" /t REG_EXPAND_SZ /d "%DocumentsDir%"
if "%isDel%"=="Y" if not "%DocumentsDir%"=="%Current_Personal%" echo.正在删除:"%Current_Personal%" & rd /s /q "%Current_Personal%">nul 2>nul

::##########################『桌面』##########################
echo 正在处理『桌面』...
if not exist "%DesktopDir%" md "%DesktopDir%"
if "%isCopy%"=="Y" if not "%DesktopDir%"=="%Current_Desktop%" copyx "%Current_Desktop%\*" "%DesktopDir%"
>nul 2>nul call :DesktopIco %DesktopDir%
>nul 2>nul attrib -r +a +s -h "%DesktopDir%"
>nul 2>nul reg add "%regPath1%" /f /v "Desktop" /t REG_SZ /d "%DesktopDir%"
>nul 2>nul reg add "%regPath2%" /f /v "Desktop" /t REG_EXPAND_SZ /d "%DesktopDir%"
if "%isDel%"=="Y" if not "%DesktopDir%"=="%Current_Desktop%" echo.正在删除:"%Current_Desktop%" & rd /s /q "%Current_Desktop%">nul 2>nul

::##########################『下载』##########################
echo 正在处理『下载』...
if not exist "%DownloadsDir%" md "%DownloadsDir%"
if "%isCopy%"=="Y" if not "%DownloadsDir%"=="%Current_Downloads%" copyx "%Current_Downloads%\*" "%DownloadsDir%"
>nul 2>nul call :DownloadsIco %DownloadsDir%
>nul 2>nul attrib -r +a +s -h "%DownloadsDir%"
>nul 2>nul reg add "%regPath1%" /f /v "{374DE290-123F-4565-9164-39C4925E467B}" /t REG_SZ /d "%DownloadsDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{374DE290-123F-4565-9164-39C4925E467B}" /t REG_EXPAND_SZ /d "%DownloadsDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{7D83EE9B-2244-4E70-B1F5-5393042AF1E4}" /t REG_EXPAND_SZ /d "%DownloadsDir%"
if "%isDel%"=="Y" if not "%DownloadsDir%"=="%Current_Downloads%" echo.正在删除:"%Current_Downloads%" & rd /s /q "%Current_Downloads%">nul 2>nul

::##########################『收藏夹』##########################
echo 正在处理『收藏夹』...
if not exist "%FavoritesDir%" md "%FavoritesDir%"
if "%isCopy%"=="Y" if not "%FavoritesDir%"=="%Current_Favorites%" copyx "%Current_Favorites%\*" "%FavoritesDir%"
>nul 2>nul call :FavoritesIco %FavoritesDir%
>nul 2>nul attrib -r +a +s -h "%FavoritesDir%"
>nul 2>nul reg add "%regPath1%" /f /v "Favorites" /t REG_SZ /d "%FavoritesDir%"
>nul 2>nul reg add "%regPath2%" /f /v "Favorites" /t REG_EXPAND_SZ /d "%FavoritesDir%"
if "%isDel%"=="Y" if not "%FavoritesDir%"=="%Current_Favorites%" echo.正在删除:"%Current_Favorites%" & rd /s /q "%Current_Favorites%">nul 2>nul

::##########################『图片』##########################
echo 正在处理『我的图片』...
if not exist "%PicturesDir%" md "%PicturesDir%"
if "%isCopy%"=="Y" if not "%PicturesDir%"=="%Current_My_Pictures%" copyx "%Current_My_Pictures%\*" "%PicturesDir%"
>nul 2>nul call :PicturesIco %PicturesDir%
>nul 2>nul attrib -r +a +s -h "%PicturesDir%"
>nul 2>nul reg add "%regPath1%" /f /v "My Pictures" /t REG_SZ /d "%PicturesDir%"
>nul 2>nul reg add "%regPath2%" /f /v "My Pictures" /t REG_EXPAND_SZ /d "%PicturesDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{0DDD015D-B06C-45D5-8C4C-F59713854639}" /t REG_EXPAND_SZ /d "%PicturesDir%"
if "%isDel%"=="Y" if not "%PicturesDir%"=="%Current_My_Pictures%" echo.正在删除:"%Current_My_Pictures%" & rd /s /q "%Current_My_Pictures%">nul 2>nul

::##########################『视频』##########################
echo 正在处理『视频』...
if not exist "%VideosDir%" md "%VideosDir%"
if "%isCopy%"=="Y" if not "%VideosDir%"=="%Current_My_Video%" copyx "%Current_My_Video%\*" "%VideosDir%"
>nul 2>nul call :VideosIco %VideosDir%
>nul 2>nul attrib -r +a +s -h "%VideosDir%"
>nul 2>nul reg add "%regPath1%" /f /v "My Video" /t REG_SZ /d "%VideosDir%"
>nul 2>nul reg add "%regPath2%" /f /v "My Video" /t REG_EXPAND_SZ /d "%VideosDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{35286A68-3C57-41A1-BBB1-0EAE73D76C95}" /t REG_EXPAND_SZ /d "%VideosDir%"
if "%isDel%"=="Y" if not "%VideosDir%"=="%Current_My_Video%" echo.正在删除:"%Current_My_Video%" & rd /s /q "%Current_My_Video%">nul 2>nul

::##########################『音乐』##########################
echo 正在处理『音乐』...
if not exist "%MusicDir%" md "%MusicDir%"
if "%isCopy%"=="Y" if not "%MusicDir%"=="%Current_My_Music%" copyx "%Current_My_Music%\*" "%MusicDir%"
>nul 2>nul call :MusicIco %MusicDir%
>nul 2>nul attrib -r +a +s -h "%MusicDir%"
>nul 2>nul reg add "%regPath1%" /f /v "My Music" /t REG_SZ /d "%MusicDir%"
>nul 2>nul reg add "%regPath2%" /f /v "My Music" /t REG_EXPAND_SZ /d "%MusicDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{A0C69A99-21C8-4671-8703-7934162FCF1D}" /t REG_EXPAND_SZ /d "%MusicDir%"
if "%isDel%"=="Y" if not "%MusicDir%"=="%Current_My_Music%" echo.正在删除:"%Current_My_Music%" & rd /s /q "%Current_My_Music%">nul 2>nul

::##########################『保存的游戏』##########################
echo 正在处理『保存的游戏』...
if not exist "%SavedGamesDir%" md "%SavedGamesDir%"
if "%isCopy%"=="Y" if not "%SavedGamesDir%"=="%Current_Saved_Games%" copyx "%Current_Saved_Games%\*" "%SavedGamesDir%"
>nul 2>nul call :SavedGamesIco %SavedGamesDir%
>nul 2>nul attrib -r +a +s -h "%SavedGamesDir%"
>nul 2>nul reg add "%regPath1%" /f /v "{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}" /t REG_SZ /d "%SavedGamesDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}" /t REG_EXPAND_SZ /d "%SavedGamesDir%"
if "%isDel%"=="Y" if not "%SavedGamesDir%"=="%Current_Saved_Games%" echo.正在删除:"%Current_Saved_Games%" & rd /s /q "%Current_Saved_Games%">nul 2>nul

::##########################『联系人』##########################
echo 正在处理『联系人』...
if not exist "%ContactsDir%" md "%ContactsDir%"
if "%isCopy%"=="Y" if not "%ContactsDir%"=="%Current_Contacts%" copyx "%Current_Contacts%\*" "%ContactsDir%"
>nul 2>nul call :ContactsIco %ContactsDir%
>nul 2>nul attrib -r +a +s -h "%ContactsDir%"
>nul 2>nul reg add "%regPath1%" /f /v "{56784854-C6CB-462B-8169-88E350ACB882}" /t REG_SZ /d "%ContactsDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{56784854-C6CB-462B-8169-88E350ACB882}" /t REG_EXPAND_SZ /d "%ContactsDir%"
if "%isDel%"=="Y" if not "%ContactsDir%"=="%Current_Contacts%" echo.正在删除:"%Current_Contacts%" & rd /s /q "%Current_Contacts%">nul 2>nul

::##########################『链接』##########################
echo 正在处理『链接』...
if not exist "%LinksDir%" md "%LinksDir%"
if "%isCopy%"=="Y" if not "%LinksDir%"=="%Current_Links%" copyx "%Current_Links%\*" "%LinksDir%"
>nul 2>nul call :LinksIco %LinksDir%
>nul 2>nul attrib -r +a +s -h "%LinksDir%"
>nul 2>nul reg add "%regPath1%" /f /v "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}" /t REG_SZ /d "%LinksDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}" /t REG_EXPAND_SZ /d "%LinksDir%"
if "%isDel%"=="Y" if not "%LinksDir%"=="%Current_Links%" echo.正在删除:"%Current_Links%" & rd /s /q "%Current_Links%">nul 2>nul

::##########################『搜索』##########################
echo 正在处理『搜索』...
if not exist "%SearchesDir%" md "%SearchesDir%" 
if "%isCopy%"=="Y" if not "%SearchesDir%"=="%Current_Searches%" copyx "%Current_Searches%\*" "%SearchesDir%"
>nul 2>nul call :SearchesIco %SearchesDir%
>nul 2>nul attrib -r +a +s -h %SearchesDir%
>nul 2>nul reg add "%regPath1%" /f /v "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}" /t REG_SZ /d "%SearchesDir%"
>nul 2>nul reg add "%regPath2%" /f /v "{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}" /t REG_EXPAND_SZ /d "%SearchesDir%"
if "%isDel%"=="Y" if not "%SearchesDir%"=="%Current_Searches%" echo.正在删除:"%Current_Searches%" & rd /s /q "%Current_Searches%">nul 2>nul

::##########################『MediaPlayer』##########################
echo 正在处理『MediaPlayer』...
>nul 2>nul reg add "HKCU\Software\Microsoft\MediaPlayer\Preferences" /f /v "TrackFoldersDirectories0" /t REG_SZ /d "%MusicDir%"
>nul 2>nul reg add "HKCU\Software\Microsoft\MediaPlayer\Preferences" /f /v "TrackFoldersDirectories1" /t REG_SZ /d "%PicturesDir%"
>nul 2>nul reg add "HKCU\Software\Microsoft\MediaPlayer\Preferences" /f /v "TrackFoldersDirectories2" /t REG_SZ /d "%VideosDir%"
>nul 2>nul reg add "HKCU\Software\Microsoft\MediaPlayer\Preferences\HME\LastSharedFolders" /f /v "Folders0" /t REG_SZ /d "%MusicDir%"
>nul 2>nul reg add "HKCU\Software\Microsoft\MediaPlayer\Preferences\HME\LastSharedFolders" /f /v "Folders1" /t REG_SZ /d "%PicturesDir%"
>nul 2>nul reg add "HKCU\Software\Microsoft\MediaPlayer\Preferences\HME\LastSharedFolders" /f /v "Folders2" /t REG_SZ /d "%VideosDir%"

::##########################『图标缓存』##########################
echo 正在处理『图标缓存』...
>nul 2>nul attrib -r -a -s -h "%USERPROFILE%\Local Settings\Application Data\IconCache.db"
>nul 2>nul del /f /q "%USERPROFILE%\Local Settings\Application Data\IconCache.db"
taskkill /f /im explorer.exe
start explorer.exe
pause
goto :EOF

:CreateRedReg
(
echo.Set oArgs = WScript.Arguments
echo.RegValue = CreateObject^("Wscript.Shell"^).RegRead^(oArgs^(0^)^)
echo.wscript.echo RegValue
)>"%cd%RedReg.vbs"
goto :EOF

:PersonalIco
	del "%*\desktop.ini"
	(
	echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21770
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-112
	echo IconFile=%%SystemRoot%%\system32\shell32.dll
	echo IconIndex=-235ter%%HP%\Documents\desktop.ini
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:DesktopIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21769
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-183
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:DownloadsIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21798
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-184
	)>"%*\desktop.ini"
	echo attrib -r +a +s +h "%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:FavoritesIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21796
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-115
	echo IconFile=%%SystemRoot%%\system32\shell32.dll
	echo IconIndex=-173
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:PicturesIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21779
	echo InfoTip=@%%SystemRoot%%\system32\shell32.dll,-12688
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-113
	echo IconFile=%%SystemRoot%%\system32\shell32.dll
	echo IconIndex=-236
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:VideosIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21791
	echo InfoTip=@%%SystemRoot%%\system32\shell32.dll,-12690
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-189
	echo IconFile=%%SystemRoot%%\system32\shell32.dll
	echo IconIndex=-238
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:MusicIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21790
	echo InfoTip=@%%SystemRoot%%\system32\shell32.dll,-12689
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-108
	echo IconFile=%%SystemRoot%%\system32\shell32.dll
	echo IconIndex=-237
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:SavedGamesIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21814
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-186
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:ContactsIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%CommonProgramFiles%%\system\wab32res.dll,-10100
	echo InfoTip=@%%CommonProgramFiles%%\system\wab32res.dll,-10200
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-181
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:LinksIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-21810
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-185
	echo DefaultDropEffect=^4
	echo [LocalizedFileNames]
	echo RecentPlaces.lnk=@shell32.dll,-37217
	echo Desktop.lnk=@shell32.dll,-21769
	echo Downloads.lnk=@shell32.dll,-21798
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF

:SearchesIco
	del "%*\desktop.ini"
	(echo [.ShellClassInfo]
	echo LocalizedResourceName=@%%SystemRoot%%\system32\shell32.dll,-9031
	echo IconResource=%%SystemRoot%%\system32\imageres.dll,-18
	echo [LocalizedFileNames]
	echo Indexed Locations.search-ms=@searchfolder.dll,-32820
	echo Everywhere.search-ms=@searchfolder.dll,-32822
	)>"%*\desktop.ini"
	attrib -r +a +s +h "%*\desktop.ini"
goto :EOF



下面是copyX.au3源码

au3代码是来自百度的某个文章

#NoTrayIcon

#pragma compile(FileDescription, '简单调用Windows自带复制对话框复制文件或文件夹')
#pragma compile(FileVersion, 1.0.0.0)
#pragma compile(ProductName, Leo)
#pragma compile(ProductVersion, 1.0.0.0)
#pragma compile(LegalCopyright, Copyright ?  2020)
#pragma compile(x64, false)
#pragma compile(UPX, true)
#pragma compile(Compression, 9)
#pragma compile(Console, true)



#include <APIShellExConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPIShellEx.au3>

Global $bOverWrite = False, $bHelp = False
Global $srcPath = '', $dstPath = ''


For $i = 1 To $CmdLine[0]
    If $CmdLine[$i] = '/y' Then
        $bOverWrite = True
    ElseIf $CmdLine[$i] = '/?' Then
        $bHelp = True
    ElseIf $srcPath = '' Then
        $srcPath = $CmdLine[$i]
    ElseIf $dstPath = '' Then
        $dstPath = $CmdLine[$i]
    EndIf
Next


If $bHelp Or $srcPath = '' Or $dstPath = '' Then
    ConsoleWrite("调用Windows自带的复制文件对话框来复制文件。" & @CRLF & @CRLF & _
                 "CopyX [/Y] source destination" & @CRLF & @CRLF & @TAB & _
                 "/Y             不提示直接覆盖目标文件。" & @CRLF & @TAB & _
                 "source         指定要复制的文件。" & @CRLF & @TAB & _
                 "destination    为新文件指定目录和/或文件名。" & @CRLF)
    Exit -1
EndIf

If FileExists($srcPath) <> 1 Then
    ConsoleWriteError('复制失败, 源文件不存在!')
    Exit -1
EndIf

If $bOverWrite Then
     _WinAPI_ShellFileOperation($srcPath, $dstPath, $FO_COPY, BitOR($FOF_NOCONFIRMATION, $FOF_NOCONFIRMMKDIR))
     Global $ret = @extended
Else
     _WinAPI_ShellFileOperation($srcPath, $dstPath, $FO_COPY, $FOF_SIMPLEPROGRESS)
     Global $ret = @extended
EndIf


If $ret <> 0 Then
    ConsoleWriteError("复制失败,错误代码: " & $ret & " 参考: https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_ShellFileOperation.htm")
    Exit $ret
Else
    Exit 0
EndIf
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值