0

i am try to Use Like This

Cmd:(ask) t0rrent File Path
User: Enters Nothing (press enter)
Code: set variable "%file%" to %USERPROFILE%\Downloads (Downloads folder)

But The %null% no works

Here is my Code

@echo off
set /p file=t0rrent File Path (Default is Download Folder) 
if %file% == %null%(
echo set file=%USERPROFILE%\Downloads
)
timeout /t 1
cd %path%
CodeFoxy
  • 1
  • 2
  • 1
    1. `path` is a special variable established by the system (sequence of directories searched for an executable if it's not in the logged directory). Use another name. 2. The syntax `SET "var=value"` (where value may be empty; in which case `var` becomes *undefined*) is used to ensure that any stray trailing spaces are NOT included in the value assigned. 3. `null` is undefined so will be replaced by *nothing* hence the `if` statement becomes `if %path% == (` which is a syntax error. Both sides of any comparison-operator (`==` here) must be non-empty strings. There must be a space before `(` – Magoo Aug 01 '22 at 08:57
  • 4. Batch is sensitive to spaces in an ordinary string `SET` statement. `SET FLAG = N` sets a variable named "FLAG " to a value of " N". Remove the spaces from **both** sides of the `=`. – Magoo Aug 01 '22 at 08:59
  • Magoo write already all corrections which must be applied to posted code. I recommend to read additionally: __1.__ [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/a/41461002/3074564) __2.__ [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) __3.__ [How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?](https://stackoverflow.com/a/49834019/3074564) – Mofi Aug 01 '22 at 09:01
  • By the way: The user has the choice to define any folder as downloads folder. `%USERPROFILE%\Downloads` is just the default user shell folder and does not exist on any of my Windows machines as I took the freedom to change the folder for downloads to a different folder on a different drive than the system drive. See [Get the Windows Download folder's path (Download shell folder) in a batch file](https://stackoverflow.com/a/27463505/3074564). – Mofi Aug 01 '22 at 09:07
  • Why not simply replace lines `2`, `3`, `4` and `5` with **2.** ```Set "file=%USERPROFILE%\Downloads"```, **3.** ```Set /P "file=t0rrent File Path [Default:%file%]>"```. Using this method, if nothing is typed before the `[ENTER]` is pressed, the value of `%file%` will not become nothing/undefined, it will remain in the state it was before the prompt. – Compo Aug 01 '22 at 10:28

0 Answers0