Home > OS >  CMD forgets file location (The system cannot find the file specified.)
CMD forgets file location (The system cannot find the file specified.)

Time:10-07

Started programming a little while ago, and wanted to do a simple program that can sort through images via user input. I wanted to do this via cmd/powershell because I assume it'd be the faster way to do it and it's easier than, say, C or C (Please note I'm not the best at this)

I currently have the following:

@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

The problem i'm running is that it returns "The system cannot find the file specified." Whenever the move command is sent (because it somehow looses the file info??)

CodePudding user response:

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!
)

(repeat for options 2 & 1)

Notes: Because delayedexpansion has been invoked, the "variable" !errorlevel! is the value of errorlevel as it has changed within the loop, and similarly for choicemade.

Since you want to taskkill regardless of the option taken, include it here - After setting choicemade

I've added option Q for Quit. Since it's the 4th character in the /c string, pressing q will set errorlevel to 4

":eof" (with the colon) is defined by cmd as physical end-of-file

if /i makes the match case-insensitive.

move "%%f" .... because %%f may contain spaces.

The goto end statements can be omitted so that the for loop merely proceeds to the next value.

IMHO, it's not good practice to use cmd's keywords (like sort) as labels or variable-names.

"loose" means "not tight" or "unleash". "lose" means "not win" or "to be deprived of, or cease to have or retain (something)". You need to lose the extra o,

  • Related