不久前開始編程,想做一個簡單的程式,可以通過用戶輸入對影像進行排序。我想通過 cmd/powershell 來做到這一點,因為我認為它是更快的方法,而且比 C 或 C 更容易(請注意我不是最擅長的)
我目前有以下內容:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
cd "C:\img\Unsorted"
:SORT
FOR /R %%f IN (*.jpg *.png *.gif *.jpeg) DO (
echo Current file is: %%f
start "" "D:\Downloads\ImageGlass_Kobe_8.6.7.13_x64\ImageGlass.exe" %%f
CHOICE /N /C 123 /M "PICK A NUMBER (1 (Folder A), 2 (Folder B), or 3(Delete))"%1
IF ERRORLEVEL ==3 GOTO THREE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE
GOTO END
:THREE
echo Current file is: %%f ::This is where the output is: 'Current file is: %f' which clearly indicates it forgot the file
move %%f "C:\img\Delete"
echo To the trash it goes!
taskkill /IM ImageGlass.exe
GOTO END
:TWO
echo Folder B Selected
taskkill /IM ImageGlass.exe
move %%f "C:\img\FolderB"
GOTO END
:ONE
echo Folder A
taskkill /IM ImageGlass.exe
move %%f "C:\img\FolderA"
GOTO END
)
:END
goto SORT
我正在運行的問題是它回傳“系統找不到指定的檔案”。每當發送移動命令時(因為它以某種方式丟失了檔案資訊??)
uj5u.com熱心網友回復:
CHOICE /N /C 123Q /M "PICK A NUMBER (1 (Folder A), 2 (Folder B), or 3(Delete))"%1
set "choicemade=option!errorlevel!"
taskkill /IM ImageGlass.exe
if /i "!choicemade!"=="option4" goto :eof
if /i "!choicemade!"=="option3" (
echo Current file is: %%f
move "%%f" "C:\img\Delete"
echo To the trash it goes!
)
(對選項 2 和 1 重復)
注意:因為delayedexpansion已被呼叫,所以“變數”!errorlevel!是 的值,errorlevel因為它在回圈中發生了變化,對于choicemade.
既然你想taskkill不管采取什么選項,把它包括在這里 -設定后choicemade
我Q為Q uit 添加了選項。由于它是字串中的第 4 個字符,因此/c按下q會將 errorlevel 設定為4
":eof"(帶冒號)定義cmd為物理檔案結尾
if /i使匹配不區分大小寫。
move "%%f" ....因為%%f可能包含空格。
goto end可以省略這些陳述句,以便for回圈僅進行到下一個值。
恕我直言,使用cmd's 關鍵字(如sort)作為標簽或變數名并不是一個好習慣。
“松”的意思是“不緊”或“釋放”。“失去”是指“不贏”或“被剝奪,或不再擁有或保留(某物)”。你需要失去額外的o,
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/515751.html
標籤:排序批处理文件命令
下一篇:使用批處理檔案更改PC名稱
