China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-10 12:08
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Call the WinRAR program directly from a batch file View 1,311 Replies 14
Original Poster Posted 2008-11-16 14:06 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
How can I use a batch file to directly call the system's WinRAR program, no matter which drive the compression program is installed on?!!!
Floor 2 Posted 2008-11-16 14:36 ·  中国 福建 福州 连江县 电信
中级用户
★★
Credits 356
Posts 115
Joined 2004-07-27 00:00
22-year member
UID 29114
Gender Male
Status Offline
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
kongzi +1 2008-11-16 15:22
Floor 3 Posted 2008-11-16 15:22 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
Many thanks to balinger, but I tried running it, and why does it exit after pressing any key to continue? It didn't run the WinRAR program!
Floor 4 Posted 2008-11-16 15:41 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
@echo off
if exist "C:\Program Files\WinRAR\WinRAR.exe" (
set WinRAR_Path=C:\Program Files\WinRAR\WinRAR.exe
) else (
reg export "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe" tmp.reg >nul
for /f "skip=3 delims== tokens=2" %%a in ('type tmp.reg') do (
set WinRAR_Path=%%~a
call set WinRAR_Path=%%WinRAR_Path:\\=\%%
del tmp.reg
goto next
)
)

:next
start "" "%WinRAR_Path%" d "archive filename" "filename to delete"

That damn BUG in reg.exe... if I use reg query directly it drops characters, so there's no choice but to export first.

[ Last edited by tireless on 2008-11-16 at 17:38 ]
Floor 5 Posted 2008-11-16 15:46 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
What I want is to write a batch file to traverse the system's rar archives and call the WinRAR command line to delete a certain file inside the rar archives. How should this batch file be written? Thanks!!! winrar d deletes files inside an archive.

[ Last edited by kongzi on 2008-11-16 at 15:48 ]
Floor 6 Posted 2008-11-16 15:49 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
The code in post #4 has been updated.

[ Last edited by tireless on 2008-11-16 at 15:54 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
kongzi +1 2008-11-16 16:00
Floor 7 Posted 2008-11-16 16:00 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
I tried running it and got an error. :(
Floor 8 Posted 2008-11-16 16:01 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
What is the error message?
Floor 9 Posted 2008-11-16 16:02 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
Let me explain it more clearly. I want to write a batch file to traverse the system's rar archives, and if an archive contains 1.exe, call the WinRAR command line to delete the program 1.exe from that rar archive. How should this batch file be written? Thanks!!! winrar d deletes files inside an archive.
Floor 10 Posted 2008-11-16 16:05 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
Originally posted by tireless at 2008-11-16 04:01 PM:
What is the error message?

---------------------------
C:\Program
---------------------------
Windows cannot find the file 'C:\Program'. Please make sure the filename is correct, and then try again. To search for a file, click the "Start" button, and then click "Search".
---------------------------
OK
---------------------------
Floor 11 Posted 2008-11-16 16:07 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
for /d %%i in (C,D,E,F,G,H,I,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z\*.rar) do (
IF exist %%i: (
winrar.exe d %%c\*.rar 1.exe
)
)
This is what I wrote, definitely not correct. This only traverses archive files under the root directories of the drives.
Floor 12 Posted 2008-11-16 16:09 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
Originally posted by kongzi at 2008-11-16 04:05 PM:

---------------------------
C:\Program
---------------------------
Windows cannot find the file 'C:\Program'. Please make sure the filename is correct, and then click Start ...

Sorry, I got one part wrong. Try the code in post #4 again.
Floor 13 Posted 2008-11-16 16:24 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
Many thanks to tireless, the program can run now, but it doesn't seem to have achieved the effect I expected.
Floor 14 Posted 2008-11-16 16:41 ·  中国 北京 鹏博士BGP
新手上路
Credits 9
Posts 9
Joined 2007-12-05 21:35
18-year member
UID 104786
Gender Male
Status Offline
Floor 15 Posted 2008-11-16 17:13 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
This only searches for .rar files under the root directories of the drives:
@echo off
if exist "C:\Program Files\WinRAR\WinRAR.exe" (
set WinRAR_Path=C:\Program Files\WinRAR\WinRAR.exe
) else (
reg export "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe" tmp.reg >nul
for /f "skip=3 delims== tokens=2" %%a in ('type tmp.reg') do (
set WinRAR_Path=%%~a
call set WinRAR_Path=%%WinRAR_Path:\\=\%%
del tmp.reg
goto next
)
)

:next
for %%A in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist %%A: (
for %%a in (%%A:\*.rar) do (
start "" "%WinRAR_Path%" d -INUL "%%a" "1.exe"
)
)
)


If you want to search for .rar files including subdirectories, change:

for %%a in (%%A:\*.rar)

to:

for /r %%A: %%a in (*.rar)

[ Last edited by tireless on 2008-11-16 at 17:35 ]
Forum Jump: