Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Command line - Some questions


01 Apr 2014   #1

Windows 7 Ultimate x32
 
 
Command line - Some questions

I've created a batch file for zipping selected items in a folder.
(The file is placed in 'Send to').


If I use the following code:
for %%* in (.) do set CurrentFolder=%%~n* "C:\Program Files\WinRar\WinRar" a -afzip "%CurrentFolder%.xpi"
  • The file name is that of the current folder (correct).
  • All files are archived whether I select one file or multiple files (wrong).
  • Selected folders are not archived (wrong).
If I use the following code:
set file=%~f1 "C:\Program Files\WinRar\WinRar" a -afzip "%file:~0,-4%.xpi" %1
  • The file name is that of the file on which I right click (correct).
  • Only that file is archived even if multiple files are selected (wrong).


How can I know if a single item is selected or more?
What's the condition syntax?
How can I include folders in the archive?


Thank you.

My System SpecsSystem Spec
.

01 Apr 2014   #2

Windows 7 32 bit
 
 

The %1 should be wrapped in double quotes in case there's a space in the file path.

But as to multiple selections, this is what I was talking about with "single instance" behavior. What Explorer does is launch the program for each file selected during the right click. The only way to avoid getting a copy of the program per file is single instance. Meaning the first copy of the program to run has to get control of some system object or file. Subsequent copies try and fail, since the first already has the resource. So secondary copies use some means to transfer the command tail to the first copy. The first copy is expecting this and has the mechanism to receive it.

It's tough to do with batch. A better choice may be a scripting language. There ae many free ones. Python, AutoHotkey, VBScript etc..

Passing the command tail uses IPC or InterProcess Communication. There are many methods. Which is "easy" tends to vary with the language used. But you might check some VBScript or Python archives. You might find some already written that may be adaptable to your task.

Edit: this site is a good source:
http://www.planetsourcecode.com/vb/default.asp?lngWId=1
My System SpecsSystem Spec
01 Apr 2014   #3

Windows 7 Ultimate x32
 
 

Thank you.
You're a good teacher.

The %1 was wrapped in double quotes when I ran it. The mistake was in the pasting here.

I'll try that site and also write to the developer of the script you mentioned.
My System SpecsSystem Spec
.


01 Apr 2014   #4

Windows 7 Ultimate x32
 
 

My System SpecsSystem Spec
02 Apr 2014   #5

Windows 7 32 bit
 
 

You're welcome. If I did VB regularly I'd be on that planet source code all the time. Many good libraries free to use there.
My System SpecsSystem Spec
02 Apr 2014   #6

Windows 7 Ultimate x32
 
 

Thank you so much.
I'll update if I get a solution.
My System SpecsSystem Spec
02 Apr 2014   #7

Windows 7 32 bit
 
 

Ok. Btw if you have Visual Basic I believe it does single instance just by clicking an option. I'm not sure about VB script.
My System SpecsSystem Spec
02 Apr 2014   #8

Windows 7 Ultimate x32
 
 

Unfortunately I don't.
I appreciate your kindness.

batch file - Command line - Some questions - Super User
My System SpecsSystem Spec
03 Apr 2014   #9

Windows 7 32 bit
 
 

I found one in VBScript"http
? vbscript ? Ensure single instance of the script running at time.

At the bottom of the function where it has the instnace count, test for 1, if first instance overwrite temp file with the file or foldername from the command line. If the count is greater than 1, append file or folder name to the temp file. In the first instance you need to set some timer or other means to guess when additional instances have quit appending data. Next step of main program is to read the temp file and process, then quit.

Code:
If ncount = 1 then
' overwrite file with command tail here
Elseif ncount>1 then
' The script got executed more than once. Script EXIT
' but only after appending command tail to file
' add code to append file with command tail here
wscript.quit
Edit: As good programming practice you would want to return the instance number out of the function(make it a function instead of subroutine etc..) instead of handling everything inside it. But it makes it clearer to show what to do inline I think.
My System SpecsSystem Spec
03 Apr 2014   #10

Windows 7 Ultimate x32
 
 

Many Thanks.

When using
Code:
for %%* in (.) do set CurrentFolder=%%~n*
"C:\Program Files\WinRar\WinRar" a -afzip -r "%CurrentFolder%.xpi"
, multiple files are archived into a single file.

Do you still think the script might help?
I'm not a pro.
My System SpecsSystem Spec
Reply

 Command line - Some questions




Thread Tools



Similar help and support threads for2: Command line - Some questions
Thread Forum
UAC bug with runas from command line? General Discussion
How can I set this via command-line or registry? Customization
Gpedit via command line Performance & Maintenance
Command Line General Discussion
Can you boot from the command line? Chillout Room

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd

All times are GMT -5. The time now is 11:29 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33