在C:/Windows目录下新建一个cp.bat 贴入以下代码保存即可
@echo off
setlocal enabledelayedexpansion
:: 智能路径格式转换器
:ConvertPath
set "path=%~1"
set "path=!path:/=\!"
set "path=!path:\\=\!"
set "path=!path:./=!"
if "!path:~0,2!"==".." set "path=!path:~2!"
set "%~1=!path!"
goto :eof
:: 主程序
if "%~1"=="" (
echo Usage: cp.bat [source] [destination]
echo or: cp.bat [source] [destination directory]
exit /b 1
)
:: 转换源路径格式
set "source=%~1"
call :ConvertPath source
:: 转换目标路径格式
set "destination=%~2"
call :ConvertPath destination
:: 智能目录检测和路径补全
if exist "%destination%\" (
set "destination=%destination%\%~nx1"
) else if not exist "%destination%" (
echo %destination%|findstr "[\\/]$" >nul
if errorlevel 1 set "destination=%destination%\%~nx1"
)
:: 执行复制操作
if not exist "%source%" (
echo Error: Source file not found - "%source%"
exit /b 1
)
echo Copying: "%source%" to "%destination%"
copy /Y "%source%" "%destination%" >nul
if errorlevel 1 (
echo Error: Copy failed. Check destination path.
exit /b 1
) else (
echo Success: File copied
)
endlocal |