將文件移到另一個文件夾改變文件擴展名可以與也做
- 選擇文件並按下克Ctrl + C鍵(複印),
- 將目標文件夾並按下Ctrl + V鍵(粘貼)
- 按壓F2用於開始重命名文件,
- 改變文件擴展名和按壓返回。
或可替代
- 選擇文件並單擊移動到Windows資源管理器的命令,
- 在打開的窗口中選擇目標文件夾,然後點擊按鈕移動,
- 導航到目標文件夾和
- 更改文件擴展名有F2,修改文件擴展名並按RETURN。
而對於這樣的任務,最有用的是一個文件管理器像總指揮官同時移動選定的文件(S)從左至右或從右到左文件夾窗格它支持改變文件擴展名的使用。
但是,這裏是一個批處理腳本,您可能會使用它幷包含一些擴展,以檢測用戶必須手動輸入路徑和文件擴展名時可能出現的一些可能的錯誤。它可以通過更多的錯誤檢查來增強。
@echo off
cls
echo.
rem Is the batch file called without an argument/parameter?
if "%~1" == "" (
echo Call %~nx0 always with name of a file with full path.
echo.
echo For example:
echo.
echo %~nx0 "C:\Path to folder\with file to\move with new extension.txt"
echo.
pause
goto :EOF
)
if not exist "%~1" (
echo Error: There is no file
echo.
echo %~1
echo.
pause
goto :EOF
)
if exist "%~1\" (
echo Error: The argument
echo.
echo %~1
echo.
echo specifies a directory and not a file.
echo.
pause
goto :EOF
)
setlocal EnableDelayedExpansion
echo Preparing for moving the file
echo.
echo %~1
echo.
set "TargetFolder=%USERPROFILE%\Documents"
echo Please specify the target folder.
echo.
echo Default target is: %TargetFolder%
echo.
set /P "TargetFolder=Move to: "
echo.
rem Replace all/by \ in target folder path.
set "TargetFolder=!TargetFolder:/=\!"
rem If the target folder path ends with a backslash, remove the backslash.
if "!TargetFolder:~-1!" == "\" set "TargetFolder=!TargetFolder:~0,-1!"
rem Does the target folder really exist?
if not exist "!TargetFolder!\" (
echo Error: The target folder
echo.
echo !TargetFolder!
echo.
echo does not exist.
echo.
endlocal
pause
goto :EOF
)
set "NewExtension=txt"
echo.
echo Please specify the new file extension.
echo.
echo Default file extension is: %NewExtension%
echo.
set /P "NewExtension=New extension: "
echo.
rem If the new file extension starts with a point, remove the point.
if "!NewExtension:~0,1" == "." set "NewExtension=!NewExtension:~1!"
rem Windows interprets everything up to last point as file name and
rem everything from last point to end of name of file as file extension.
rem On *nix systems it is common that hidden files don't have a file
rem extension and start with a point (for hiding the file). To copy such
rem files with unusual file name on Windows like .htaccess also correct,
rem it is necessary to interpret the file extension as file name if the
rem file starts with a point and has no file extension.
if not "%~n1" == "" (
set "NewNameOfFile=%~n1.!NewExtension!"
) else (
set "NewNameOfFile=%~x1.!NewExtension!"
)
echo.
move /-Y "%~1" "!TargetFolder!\!NewNameOfFile!"
if errorlevel 1 (
endlocal
echo.
pause
) else (
endlocal
)
對於理解使用的命令以及它們如何工作,打開命令提示符窗口中,執行有下面的命令,並完全讀取顯示每個命令的所有幫助頁面非常謹慎。
cls /?
echo /?
endlocal /?
goto /?
if /?
move /?
pause /?
rem /?
set /?
setlocal /?
所以...什麼是你的問題?你有什麼代碼?它有什麼問題? – TessellatingHeckler
我試圖結合這兩個代碼重命名,然後將文件移動到特定的目錄,但我遇到了麻煩,因爲我不太確定這樣做。 >'關閉@echo 組/ P VAR =移至:%VAR% CLS 移動%1 「%VAR%」 pause' >'關閉@echo 組/ P VAR =文件名:% var% cls set/p var2 =文件類型:%var2% 重命名%1「%var%。%var2%' – FleetSakes
如果您將原始問題添加到原始問題中,將會更好。儘可能從頭開始,這樣我們可以更快地理解你的問題,並制定出答案。 – rlam12