This question already has answers here:
How to verify if a file exists in a batch file?
(3 answers)
Closed 8 years ago.
I need a batch code that will tell me if test.txt is there or not it is in the same directory as the batch file. I would like to know what I should put in the space where it says the code. Can anyone help?
rem the code
echo yes
rem the code
echo no
IF EXIST yourfilename (
echo Yes
) ELSE (
echo No
)
Note : ELSE command must be on the same line as the end of the IF command.
To explore more type IF /? in cmd.
Related
This question already has answers here:
BATCH- echo % (print an percent sign) [duplicate]
(1 answer)
Escape percent in bat file
(1 answer)
Ignore percent sign in batch file
(6 answers)
How does the Windows Command Interpreter (CMD.EXE) parse scripts?
(8 answers)
What is the difference between % and %% in a cmd file?
(2 answers)
Closed 6 days ago.
I want the code below to work or something that does the same thing.
#echo off
echo 100%
pause
When you open the .bat file it shuld look like this.
100%
Press any key to continue . . .
So i want the echo to read out the % and not to be a part of a code.
I want it to work the same as for example
#echo off
echo hi
pause
I have only tried echo 100% because i am a noob at coding so i dont know what else to try.
The percent sign has special meaning in (Windows) batch files, it is used to indicate a variable. For instance, echo %username% will print the contents of the username variable.
To echo a literal % sign, you need to double it, i.e. echo 100%%
This question already has answers here:
Escape angle brackets in a Windows command prompt
(6 answers)
using batch echo with special characters
(8 answers)
Closed 9 months ago.
I want to Create a Batch File1 Which Creates a Batch File2, This Batch File2 Should then Create a txt file.
Below is the 4 lines script i Want to Append to Batch File2. I need Code for Batch File1.
Please Help
echo > t.txt
:r
echo 101010101010 >> t.txt
goto r
P.S: I am new to Stack Overflow, only my account is old. until now i did not know it's True
Powers, but i'm realising.. (excuse me for being informal)
Refer to How to Escape Characters
BATCHFILE1.bat that can create the second batch file BATCHFILE2.bat
#echo off
Title I am the BatchFile1.bat who wants to create the BatchFile2.bat
(
echo #echo off
echo echo^>t.txt
echo :r
echo echo 101010101010^>^>t.txt
echo goto r
)>BATCHFILE2.bat
Batch File2.cmd should look like this:
#CD . 1>"t.txt" 2>NUL || Exit /B
:r
#(Echo 101010101010) 1>>"t.txt"
#GoTo r
The first line will create your text file, unless the current directory is not writeable. Should that be the case, your batch file will simply close without entering the loop. The code in the loop will print your required string without including any trailing spaces.In order to stop writing to the file, you will need to enter Ctrl+C
Therefore to output it from Batch File1.cmd you'd need:
#(
Echo #CD . 1^>"t.txt" 2^>NUL ^|^| Exit /B
Echo :r
Echo #(Echo 101010101010^) 1^>^>"t.txt"
Echo #GoTo r
) 1>"Batch File2.cmd"
Using this method, you simply need to escape the usual special characters, plus any nested closing parentheses. In the above your special characters are the redirection and pipe characters.
This question already has an answer here:
Automating task for unzing a gz compressed file using windows batch script [closed]
(1 answer)
Closed 2 years ago.
I have two issues with this code I have attached below,
it doesn't delete the original file after unzip, I want the script to delete the original file from source folder
the converted file is not saved in target folder as set but it creates a tree of the directory in the same folder of the script and saved output there.
Please help me solve this issue
Sample code I have tried
#echo off
set "source=%userprofile%\Desktop\basanta\Automation\a"
set "target=%userprofile%\Desktop\basanta\Automation\b"
FOR %%A IN ("%source%\*.gz") DO (
"%programfiles%\7-zip\7z.exe" x "%%~A" -o"%target%\%%~pA"
del "%%~A" /Y
)
Please help me to write the script as described above
try: del file /f /q
try to enclose -o parameter with a quotes: "-o%target%"
This question already has answers here:
Check if any type of files exist in a directory using BATCH script
(4 answers)
Closed 5 years ago.
i want to write a batch script where i need to check if a directory is empty or not, if not empty i want to clean that particular directory. Path will passed via command line argument.
Here's some example code to get you started:
#Echo Off
If "%~1"=="" GoTo :EOF
If Not Exist "%~1\" GoTo :EOF
Dir/B/A "%~1\*"|Find /V "">Nul&&Call :CleanIt
Pause
GoTo :EOF
:CleanIt
Rem Your clean command(s) here
You should only need to add your specific code to the bottom
This question already has answers here:
Assign output of a program to a variable using a MS batch file
(12 answers)
Closed 7 years ago.
I want to store this command in a variable called code1
dir /a:d /b
so the output would be:
Folder1
Folder2
Folder3
etc...
Any ideas how to do it?
I've checked other questions and when it just sais echo is off.
Simply store the command in the variable like you say. To execute, simply expand the value:
#echo off
setlocal
:: Define a simple "macro"
set "code1=dir /a:d /b"
:: Execute the "macro"
%code1%