Help - Search - Members - Calendar
Full Version: Batch File
BleepingComputer.com > Operating Systems > Windows Vista
   
danbrownlow
Hello all, I have a little problem. I use java and javac alot and everytime I open "cmd" I have to cd to the right directory! Which can be a pain.

Well, I thought I'd make a .bat file so that when I click and open it, it would be in the right directory. I went into Notepad and typed:
CODE
cd c:\Users\<username>\Documents\Java

and saved it as a .bat file, however, when I run it, it comes up quickly and then dissapears! I tried adding pause to the end, but that was no help.
Can anyone offer any ideas?
Thanks :D
uhaligani
You will need to write the path to where the .bat file is situated.
eg The default for the command prompt is c:\users\username. so the easiest thing would be to place the bat file in that folder.
danbrownlow
It does exactly the same thing, when I start the bat file, it loads and dissapears. I wanted it to automatically change the directory so I wouldn't need to manually type it in everytime I want to compile or run a java file.
Anyone got any more ideas?
usasma
Do you run the .bat file in the cmd window? If not, then it'll just terminate when it's done. The /f switch will prevent the command prompt from closing, but I'm not familiar enough with the syntax to figure out how to do it.
uhaligani
Your syntax is corrct. I've tried every combination and it works for me. I called the bat "try" (but the name is of no significance!) I saved it to my user, which in my case is "Administrator" (I run as the "power" administrator, without a user). For the exercise I created the Folder "java". Every time it changed to that directory.
Have you tried right clicking the Command prompt and running as the Administrator, thats all I can think of?
frankblourtango
Does it give you any error if you open a dos prompt and then run it? See if it completes without any errors and returns to the prompt. I test my batches by doing that and watching them complete. Just my two cents.
danbrownlow
Yea' it runs fine when I open it via CMD by typing 'java.bat', I kind of was wondering how I could get it to run by just clicking the link file in Explorer, as I am quite lazy. Thanks for the help anyway, it works fine in CMD so thank you =]
uhaligani
I think I misunderstood your intention. I thought you were concerned with the command prompt. If you want to open Windows explorer to your Java folder, then you should open another instance of explorer on your desktop or shortcut menu. right click and in the properties , after C:\Windows\explorer.exe make a space and then C:\Users\<username>\Documents\Java. Is that what you are looking for?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.