News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Batch commands on NT based computers

Started by zemtex, June 17, 2011, 07:45:19 PM

Previous topic - Next topic

zemtex

I am trying to avvoid a program, I would prefer to avvoid an user interface. Automation is the key hereĀ  :bg
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

mineiro

Ok Sr, your winrar will be:
SET winrar="%ProgramFiles%\WinRAR\Rar.exe"

If you use the default variables, you can avoid wrong paths.
In my computer, the programfiles variable is "Arquivos de Programas", in english version is "Program Files", ..., and go on in different languages.

zemtex

Yes, I was going to do that, this is just a beta, a test-script so far. Didn't have time to put environmental variables into it yet. It works for compressing files and folders, but if you specify a long filename and feed it as a parameter to the script, it will pass as several parameters, I wanted to know if there is a workaround for this, rather than parsing it.
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

mineiro

To you deal with big names under prompt, you enclose it with commas ""
to you list all files in that dir to one file you do:
dir > list.txt
to you list all subfolders, you do with a switch /s, so if you are in c:\ and type:
dir /s > list.txt
the list.txt have all files of your harddrive. If you like to see the hidden too, so add a switch /ah: "dir /s /ah > list.txt"
the ">" say to create one file if it not exist, and if it exist, it will be writen again.
If you like to add some text inside the generated file(last line), you write with ">>"
So, about your question, you need use commas betwen each parameter:
test.bat

@echo off
echo %1
echo %2

now, type in prompt: test one "this is a second argument"

Rar, have one option: n@filename . To you see the list of rar options type in prompt "rar > options.txt | notepad options.txt"
so, to compress all files in the folder, you can generate a list.txt and after call rar.exe
dir > list.txt
rar a @list.txt
ren @list.txt myname.rar

Well I do not have played with all options of rar, but worked here.

mineiro

These examples show you how to call another bat file inside of one batch file. I set the path to rar, and if the user type some name, I set that name to variable myfile.
So, this variable is a global, all environment can see that. After, call the compress.bat, and it compress the file.
do_it.bat

@echo off
set path=%path%;"%programfiles%\winrar"
if "%1"=="" goto usage
set myfile=%1
call compress.bat
goto end
:usage
echo you need say the file to be compressed
:end


compress.bat

rar a test.rar %myfile%


So to compress some file type:
do_it somefile.ext

edited after:
The previous example of MessageBox, show you how to deal with errors.
So your compress.bat can be:
rar a test.rar %myfile%
if errorlevel 1 echo error happened

now, if you try to compress one file that don't exist, errorlevel 1 is returned by rar, and you can set some global variable.

dedndave

QuoteTo you deal with big names under prompt, you enclose it with commas ""

enclosing file and/or path strings in double-quotes allows you to handle names that contain spaces
otherwise, the batch parser interprets the spaces as parameter delimiters
when you expand certain system defaults, they contain spaces
a good example is "C:\Documents and Settings"

FORTRANS

Quote from: zemtex on June 17, 2011, 11:12:17 PM
FORTRANS: I figured out why my script failed, despite being the same as yours. When I echo some text out, I forgot to put it inside quotes (""), so it parsed some special characters as script delimiters and so the whole thing became corrupt. I now put quotes on my string outputs. But the bad thing is that the quotes is also printed to the screen, can i avvoid this somehow

Hi,

   I've had REM statements do bad things, which surprised
me a bit.  So I got into the habit of using double quotes (")
everywhere.  The other option is to use the escape character
(^) to clue the parser to not interpret some characters
as operators.  Try the following in a BATch file to see how
it works:

ECHO ^> This is a test!

A minor warning; the use of the escape character has proven
to be a bit flakey for me.  Though that may be the use of
more than one operating system by me.

Regards,

Steve N.

dedndave

if you want to comment a batch file, start the line with double colons "::"
the parser sees it as a label, albeit an illegal one, and ignores it

i read someplace that more recent versions of DOS accept semicolons - not sure about that one