ms dos - Break commands into new line in Dos command
2014-07
I am trying to copy a few commands into DOS from a notepad file, and when I copy them I want them to be on new lines for each command.
Input: cd.. mkdir 568 cd 568
When I copy this into DOS I want something like
cd..
mkdir 568
cd 568
I tried cd.. ^ mkdir 568 ^ cd 568
using different characters but no luck.
You were right the Carat is useless in the situation of putting multiple commands on One single line, for the purpose of processing them one after the other.
I tested many of the methods and finnaly found the one that best works in your example above. & or &&
CLS && H: && CD\ && CD "new folder" && MKDIR stuff && CD stuff
H: is my target drive
One fail on the line, and the rest of the items on the line will not process (see &).
Mine has some more kludgy things in it so It would repeat.
That ^ worked the same way as this (below) does, except in a fail that bails out.
CLS
H:
CD\
CD "new folder"
MKDIR stuff
CD Stuff
This ^ can also be pasted into the CMDprompt for windows 7 and works fine.
The conditional processing symbols for issueing multiple commands from the same prompt and to act based on the results of a command.
The ampersand (&) separates multiple commands on one command line.
The parentheses groups multiple commands.
The semicolon or comma (; ,) separate command parameters.
The caret (^) cancels a subsequent command symbol's special meaning so you can
use a command symbol as text.
The double ampersand (&&) causes the command following this symbol to run only
if the command preceding the symbol is successful.
The double pipe (||) causes the command following this symbol to run only if the
command preceding the symbol fails.
Is there an MS-DOS command that allows me to delete all files except one?
Consider as an example the following files:
a.001
a.002
a.003
a.exe
a.c
Is there a command to delete all files except a.c
?
You can use the for
and if
commands to accomplish this:
for %i in (*) do if not %i == a.c del %i
This goes through the current directory, and compares each file name to a.c. If it doesn't match, the file is deleted.
No, there isn't. I'd make a directory, copy the important file into it, erase ., and move the file back. Then delete the temp file.
mkdir temp
move a.c temp
erase *.*
move temp\* .
rmdir temp
You could set the file to read only before deleting everything
attrib +r a.c
del *.*
attrib -r a.c
FOR %f IN (*.*) DO IF NOT [%f]==[a.c] DEL /Q %f
FOR /F "tokens=1-4" %%a in ('dir /a:-d /b /s %app_path%^|find /v "%file%"') DO Del /q %%a %%b %%c %%d