Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6391849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:44:21+00:00 2026-05-25T03:44:21+00:00

This is my first batch file, and also my first time with batch language

  • 0

This is my first batch file, and also my first time with batch language (I usually use UNIX and don’t know a lot about Windows commands).

I’m creating a batch file called install.bat which does all the work to install a Java application from source files. Here a snapshot of the install section:

@ECHO off
SET INSTALL_DIR=%1\
SET SRC_DIR=sources\
SET LIB_DIR=lib\
SET IMG_DIR=img\
SET BIN_DIR=bin\
SET INIT_DIR=%CD%
SET MAIN_CLASS=%SRC_DIR%\main\Main.java
SET CLASS_PATH=%LIB_DIR%log4j.jar;%LIB_DIR%jdom.jar;
SET JAR_NOM=myApp.jar
SET JAR_MF=MANIFEST.MF

:BEGIN
CLS
ECHO Checking directory...
IF EXIST %INSTALL_DIR% (
    GOTO Ask_Overwrite 
) ELSE (
    GOTO Install
)

:Ask_overwrite
SET OVERW=Y
SET /P OVERW="The program is already installed. Overwrite? ([Y]/N): "
IF %OVERW%==N GOTO Cancel
IF %OVERW%==n GOTO Cancel
IF %OVERW%==Y (
    RD /S /Q %INSTALL_DIR% <--- Here was the error
    GOTO Install
)
IF %OVERW%==y (
    RD /S /Q %INSTALL_DIR% <--- Here was the error
    GOTO Install
)
GOTO Ask_overwrite

:Install
MD %INSTALL_DIR%   
XCOPY . %INSTALL_DIR% /E
CD /D %INSTALL_DIR%
MD %BIN_DIR%

ECHO Compiling...
javac -cp %CLASS_PATH% -sourcepath %SRC_DIR% %MAIN_CLASS% -d %BIN_DIR%

ECHO Creating JAR file...
jar cfm %JAR_NOM% %JAR_MF% -C %BIN_DIR% .

ECHO Succes! The application has been installed in %INSTALL_DIR%
GOTO CleanUp

:Abort
ECHO Abort! The application has not been installed.
GOTO CleanUp

:Cancel
ECHO Canceled by user. The application has not been installed.
GOTO END

:Cleanup
REM Code for clean up
GOTO END

:END
CD /D %INIT_DIR%
PAUSE

NOTE: The javac and jar commands are correct, at least work in my machine.

Well, the script works correctly when I test it with the INSTALL_DIR belonging to the same drive where I execute it, but if I use a target directory out of the drive where I’m executing, I have problems.

Executions without problems (called in a cmd.exe session):

C:\Users\TC\testInstall> install.bat .\..\installTarget

C:\Users\TC\testInstall> install.bat C:\Users\TC\installTarget

Execution with problems (called in a cmd.exe session):
C:\Users\TC\testInstall> install.bat D:\Documents\installTarget

The problems happen when I try to copy files specially, but also making and removing directories.

I hope someone can tell to me which options I must use in order to fix the problems.

Regards!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:44:22+00:00Added an answer on May 25, 2026 at 3:44 am

    Well, I have two mistakes that I fixed and then the script work correctly.

    The first was that I didn’t use the /d option in cd command in order to change also the drive unit. It means, C:Users\TC> cd D:\Documents is wrong, the correct command is the following: C:Users\TC> cd /d D:\Documents as well as the MS-DOS manual page indicates.

    The second error, it wasn’t actually an error, I put rm -rf %INSTALL_DIR% (like in Linux) instead of the correct Windows command rd /s/q %INSTALL_DIR%

    Now all the problems have been fixed and the script works properly 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time using joomla. I don't know if I'm using the
problem euler #5 i found the solution but i don't know why this first
Is there a way for a batch file (in this case, running on Windows
I have a windows batch file that does this: for %%s in (*.sql) do
this is my first question to stackoverflow so here it goes... I use cruise
This is my first time attempting to call an ASP.NET page method from jQuery.
This is my first time with Web services. I have to develop web services
I know I have already answered a similar question ( Running Batch File in
I have a problem. I have a batch file which imitates the UNIX cd
I've got to fix this little bug. First, let's talk about a small fact:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.