Jump to content

DOS Batch File


Recommended Posts

The Drag and Drop, (especially in your stated XP Pro x86), does not function any differently from the method you are using. Basically it is an automatic, (GUI), way of running the batch file with the dropped file as the parameter %1. The only way to archive your entire C: drive would be for you to have either provided it as THE REQUIRED PARAMETER or not to have provided a parameter at all. Since your example used a parameter in the same way, I presumed you were fully aware of this functionality.

Armed with this knowledge, try all three of my examples again and choose the one which suits your purpose.

The first example places the archive inside you source folder, the second along side the batch file and the third in the current directory.

when I run RARMe.cmd from a dos box with nothing else specified from a directory 3 levels deep:

1) Compresses the entire hard drive instead of the current directory.

2) Places the compressed file in the root of the drive instead of the current

directory.

3) Has no filename in front of the .rar extension instead of the "directoryname.rar".

when I run RARMe_2.cmd from a dos box with nothing else specified from a directory 3 levels deep:

1) Compresses the entire hard drive instead of the current directory.

2) Places the compressed file in my C:\BIN directory instead of in the current directory.

3) Has no filename in front of the .rar extension instead of the "directoryname.rar".

when I run RARMe_3.cmd from a dos box with nothing else specified from a directory 3 levels deep:

1) Compresses the entire hard drive instead of the current directory.

2) Places the compressed file properly of the current directory!!!

3) Has no filename in front of the .rar extension instead of the "directoryname.rar".

Part of the problem may be that I want to type one character (z) for z.bat without specifying any other parameter, and have it automatically determine the current directory name without the entire path, then pass that name to RAR so that it archives the files as directoryname.rar inside that directory.

Again, thanks for your efforts on my behalf.

Link to comment
Share on other sites


Wise Owl. If I use this portion of your code;

@"%ProgramFiles%\WinRAR\rar" a -r -ep1 "%~nx1.rar"

it archives the files in the correct directory, and places the archived file in that same directory, just as I desire. The only problem is that the resulting compressed archive filename is .rar with no prefix before the extension. I need the batch file to read the current directory name together with any spaces and dots in that directory name, and name the .rar file so that it matches the directory name, with the .rar extension.

Well that tells me something which I would have ascertained earlier had you provide a response to jaclaz when asked in post number 11.

r

It appears that you may not have variable expansion working, try this:

  • In your console window launch a new window using this command
    START CMD /E:ON


  • In that window use the example I've provided, (Do not omit the "%~f1\*" from the end).
  • Then let us know what happens.

Wise Owl, Many Thanks. I used this command with the /E:ON switch. Interesting that I must start a dos prompt to open a second dos prompt to do this as Norton Commander launch just shows bad filename. Nevertheless, this compresses the entire drive, and still does not pass the current directoryname to the archive filename I need.

Link to comment
Share on other sites

Part of the problem may be that I want to type one character (z) for z.bat without specifying any other parameter, and have it automatically determine the current directory name without the entire path, then pass that name to RAR so that it archives the files as directoryname.rar inside that directory.

Again, thanks for your efforts on my behalf.

I'm still not with you, where are you typing z?

If you are inside a directory and you type z, then z.bat must be either inside that directory or somewhere within %path%. If z.bat is inside the directory then it would serve little purpose so I'd assume that we're talking about the latter.

If such is the case try this as your batch file:

Z.BAT

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
FOR %%# IN (.) DO (SET CF=%%~f#
SET DN=%%~nx#)
"%PROGRAMFILES%\WINRAR\RAR" A -R -EP1 "%DN%.rar" "%CF%\*"
ENDLOCAL
GOTO :EOF

Link to comment
Share on other sites

Wise Owl,

THANKS That one works perfectly !!! Consider this problem solved. Its exactly what I needed. I am running the z.bat file from inside a bin directory located in the path statement.

Further, its an elegant solution. Yet I don't have the slightest clue how it works, LOL. But its perfect. Now I will need to spend many hours figuring out why it functions. I would never have figured this one out.

Thanks again.

Link to comment
Share on other sites

Just remember as I intimated in my first response in this topic, if your current directory already has an archive named using this method inside it then you'll be archiving it inside another!

BTW, now we've got to the bottom of your situation here's a slightly shortened version of the script, (two lines):

Z.BAT

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
FOR %%# IN (.) DO "%PROGRAMFILES%\WINRAR\RAR" A -R -EP1 "%%~nx#.rar" "%%~f#\*"

Incidentally, you may note that my name here is Yzöwl, If you look at the side panel you'll note that calling me Wise Owl throughout this conversation would be equivalent to me calling you Newbie or jaclaz MSFN SuperB!

Link to comment
Share on other sites

Just remember as I intimated in my first response in this topic, if your current directory already has an archive named using this method inside it then you'll be archiving it inside another!

BTW, now we've got to the bottom of your situation here's a slightly shortened version of the script, (two lines):

Z.BAT

@ECHO OFF & SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
FOR %%# IN (.) DO "%PROGRAMFILES%\WINRAR\RAR" A -R -EP1 "%%~nx#.rar" "%%~f#\*"

Incidentally, you may note that my name here is Yzöwl, If you look at the side panel you'll note that calling me Wise Owl throughout this conversation would be equivalent to me calling you Newbie or jaclaz MSFN SuperB!

Yzöwl, after seeing you solve this problem, how can I possibly take offense to you calling me a newbie? In comparison, I certainly am. Nevertheless, Wise Owl is certainly an appropriate name for you. LOL. In any case, your advice is duly noted and appreciated, and I will do my best to follow forum rules and conventions. I've been out of circulation for 12 years, and have much catching up to do; with Internet forums, batch files, and Visual Basic 4.0, much has changed. I certainly appreciate your patience and interest in helping me. Thanks again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...