Computing.Net > Forums > Disk Operating System > Batch file probs in W2k and XP

Batch file probs in W2k and XP

Reply to Message Icon

Original Message
Name: Major Headache
Date: November 16, 2001 at 00:02:15 Pacific
Subject: Batch file probs in W2k and XP
Comment:

I have a nice little batch file that my friend made:

copy /y/b %1+,, %0\..\.
%0\..\pack.exe %0\..\dfbase.pff %1
The first line copies a file dragged ONTO the batch file. It actually only copies it onto itself updating the file date in the process.
The next line packs the dropped file into dfbase.pff.

Here are my questions:
Why won't it work in Windows 2000 and XP? Even if I lose the copy portion, the pack doesn't work. Pack does work in 2k and XP when used in a conventional form (pack destination source1 source2 etc) so it seems it doesn't like %1 as the argument.

2. How do the % variable arguments work? I'd love to know enough to be able to use them intelligently. Is there something I could read on the subject? Using drag and drop with a bat file is very handy!


Report Offensive Message For Removal


Response Number 1
Name: ddddummy
Date: November 16, 2001 at 06:08:52 Pacific
Subject: Batch file probs in W2k and XP
Reply: (edit)

[1]
I don't believe that the %1 argument is not supported in xp/2000, although i may be wrong.
It sounds like a problem to locate pack.exe.
%0\..\pack.exe means that the batch processor (command) searches for pack.exe distinctly and ONLY in the path one level up from where the batch file lies (e.g. c:\windows\pack.exe if the batch file was c:\windows\desktop\batch.bat).
thus, you have to copy pack.exe into the appropriate directory.
Alternatively, you could also try and remove the "%0\..\" before the command, which would lead to the command being searched for according to the PATH (i hope that is right in xp..). you should then place pack.exe in c:\windows\ or something like that.

[2] The %n argument means the string value of the n-th parameter for the execution.
the zero-eth parameter %0 is always the full file/pathname to the batch file: thus, by invoking e.g. %0\..\, you get the directory one level above where the batch lies.
%1 is the first 'real' parameter. if you drag a file onto a batch, %1 is set to the full file/pathname of the dragged file.

You can test this with the following batch file:

@echo off
echo "%0" "%1" "%2" "%3" "%4"
pause

Note that if you drag more than one file onto the batch, their pathnames are assigned to %2, %3 and so on; if you just click on the batch file, only %0 is available.
if this doesn't work, it IS xp/2000's fault!

To make use of this behavior (multiple files), have a look at the "shift" batch file command in a dos command reference on the www, where you will also find various examples.

hope to have helped ;)


Report Offensive Follow Up For Removal

Response Number 2
Name: Major Headache
Date: November 16, 2001 at 11:09:51 Pacific
Subject: Batch file probs in W2k and XP
Reply: (edit)

OK, that was enough to let me figure out the following and thus have another question =)

First the %0\..\ does work, and heres why:
%0 is the path and FILE itself, i.e. c:\WINDOWS\batch.bat so the \..\ steps it down to just be c:\windows\ therefore
%0\..\pack.exe would be c:\windows\pack.exe.
(I know it works, because it works! At least in 98/ME)

Second, the difference between 98 and 2k/XP is that the latter adds quotes. So in XP you get "c:\windows\batch.bat"\..\pack.exe etc. etc. which becomes a useless text string.

All subsequent %x variables get the same quotes treatment, which leads me to my question: Is there a way in 2k/XP to not get the quotes? Is there a good resource on the web where I might find out about this?

Thanks for the info so far!!!


Report Offensive Follow Up For Removal

Response Number 3
Name: ddddummy
Date: November 16, 2001 at 15:53:22 Pacific
Subject: Batch file probs in W2k and XP
Reply: (edit)

hmm. i don't think that there is a way to do simple string manipulations just using dos commands (at least not stripping single characters...) :,(

however, i just tested this in win98, and the 98 command.com seems to have no prob recognizing something like "c:\windows\"command\"keyb.com" : you can type as many quotes as you want! has this REALLY changed in 2k/XP or could it be that there is a \ missing or so?
there are also user directory permissions in xp/2k, aren't they? can all apps write to c:\windows\ ?

i'm sorry, i don't know a special good link, but you could just enter "dos batch file programming" in google and you'll get plenty of decent sites with links (you'll have to browse a bit).

you could also write a small wrapper app for pack.exe in c or pascal that strips the quotation marks and calls pack. if you can't, contact me via email, i should be able to code that :o)


Report Offensive Follow Up For Removal

Response Number 4
Name: Laurence
Date: November 20, 2001 at 01:26:03 Pacific
Subject: Batch file probs in W2k and XP
Reply: (edit)

NT is not DOS.

Windows NT 5.0 aka 2000 and NT 5.1 aka XP
are not DOS based like
Windows 4.x aka 95/98/ME are.

Batfiles: The DOS batch file programming handbook & tutorial

You must ask your questions in a NT group,
this is the wrong place for you now.

alt.msdos.batch.nt
Or: http://groups.google.com/groups?as_ugroup=alt.msdos.batch.nt


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch file probs in W2k and XP

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge