Anyone here know batch? : I need help

I am trying to create a simple batch file that runs a game in a requested directory that the batch file is not in. However, the file directory I want to run from contains spaces. Therefore it does not work. How can I represent a space of a directory in batch so it understands. Here is the code that I have. (Sorry if it’s too long… lol)

start c:\Documents and Settings\game.exe

use quotes:

start “c:\Documents and Settings\game.exe”

There is the old dos way too:
start c:\Docum~1\game.exe

Wow… that was fast…

thanks Mmph!!

How does the old way go… like this??


start c:\Documents~1and~1Settings\game.exe

if you want to get fancy try this:

title My Super duper launcher.
color f4
echo off
cls
start “c:\Documents and Settings\game.exe”
echo program launched have a nice day.
pause

How does the old way go… like this??

no the old way is only 8 charictors per directory or file name and 3 for extension.

the first 6 letters are as usual, the 7th and 8th have to be ~1… so basically it will work for documents and settings, and program files because the space is after the 8th charictor.

Ok. What if I wanted it to open a file in:
c:\Documents and Settings[insert current username here]\game.exe

How would I represent [insert current username here] in batch? In other words, the name of the current account the user is on.

Bye the way, here is how to do the colors in DOS:
http://www.robvanderwoude.com/ntcolor.html

Do you know how to do what I posted above your handy color DOS post?

yes like this:

start “%SystemRoot%\documents and settings%username%\Whateverelse\filename.exe”

%SystemRoot% will choose the drive that windows is installed on, not everyone is on c:

%username% is whoever is logged in

Lostinspace:

There’s a whole bunch of environment variables in Windows that you can use. One of them is %USERPROFILE% , which expands to the full path to get into the user directory. I’d recommend not to use the user name only, because Vista users have their %USERPROFILE% (by default) set to C:\Users\UserName instead of C:\Documents and Settings\Blah\Blah

To see more environment variables, open up a command prompt (not DOS, there is no DOS in Windows NT based systems), and type “set”. Normally, that’s the command for "set"ting a new or modify an existing environment variable, but if you use it without arguments you’ll get a nice listing of all variables available. You might recognize some of them if you ever looked into the Windows system properties dialog :slight_smile:

Dude… you rock!! (applys to both of you)

BTW oogsnoepje: that works awesome! Thanks for the tip!

No, never ever use %SystemRoot%, I’m not sure about other versions of Windows, but on Vista it points to C:\Windows.

%USERPROFILE% is the only variable to use to (correctly) get into the user profile directory :slight_smile:

there is no DOS in Windows NT based systems

DOS stands for Disk operating system. the dos shell uses dos commands in windows NT systems.

Do you guys know what would be the best way to access the files were programs are? Would it be:

“%SystemRoot%\Program Files\bla”

All versions of Windows until 98, 98se and ME were based on (layered on top of) MS-DOS, the NT based versions (including 2k, xp, vista) of Windows are not based on MS-DOS and the command shell is just a program in which you can use DOS commands. Nothing like MS-DOS in there…

Even “ver” tells you it’s Windows :slight_smile:

Also, there are so many new commands since MS-DOS… you can open files from a network, you can use ftp, you can query driver properties, query system information, convert partitions, manage running tasks, etc. I wouldn’t say that’s MS-DOS anymore.

Anyway, this is all just nitpicking, who cares anyway :wink:

There is no “C:\Windows\Program Files” :slight_smile:
Better use %SystemDrive% instead.

I’m not sure if there’s any recommended way to get the program files directory, but I do know you’re not supposed to go there.
(especially on more recent versions of Windows where things can be blocked)

This works really well!

I’m not sure if there’s any recommended way to get the program files directory, but I do know you’re not supposed to go there.
(especially on more recent versions of Windows where things can be blocked)

Bla… it’s just not recommended to go in. If you press view files and folders you can view them anyway. As long as you know what you are doing you are fine. That is just there to stop people that do not know what they are doing from deleting an important system file.

Is there a way to delete a directory in Batch? I know you can delete a file by

 del c:\fileHere.txt

But deleting a directory is asking me are you sure and I type Y and press enter and it does not delete the directory.

All versions of Windows until 98, 98se and ME were based on (layered on top of) MS-DOS, the NT based versions (including 2k, xp, vista) of Windows are not based on MS-DOS and the command shell is just a program in which you can use DOS commands. Nothing like MS-DOS in there…

Even “ver” tells you it’s Windows :slight_smile:

Also, there are so many new commands since MS-DOS… you can open files from a network, you can use ftp, you can query driver properties, query system information, convert partitions, manage running tasks, etc. I wouldn’t say that’s MS-DOS anymore.

Anyway, this is all just nitpicking, who cares anyway :wink:
You can issue dos commands in Linux, unix, and Solaris too… it just stands for disk operating system. (it dose not stand for M$DOS, PCDOS, or AmigaDOS , when I say it)

Is there a way to delete a directory in Batch? I know you can delete a file by
yea, just do a del directory name it should work just fine for you.

That’s the reason I wrote “DOS commands” (instead of “MS-DOS commands”, which wouldn’t be the right thing to say, indeed) and only about “MS-DOS” when I was talking about how Windows was based on it and all that :wink:

The “rmdir” command does it without asking questions by default. For options about removing directory trees, type “rmdir /?”.

You can use the “/?” argument for all commands by the way :slight_smile:
“help” is also very useful to see all available commands.

just do this:

rd YourDirectoryNameHere /s /q

you can use the rmdir with a /s /q too.

You can also use the deltree command:
deltree DirectoryNameHere /y

the /y will make it so it will not prompt. deltree will only delete an empty directory. you can always just do a CD dirname, then do a del*.*, then a cd …, then the deltree.

some people even like the erase command:

erase YourDirNameHere /q /f
OR
del YourDirNameHre /q /f

the /q is quitet mode, so it will not prompt user, the /f is to get even the read only files, so use it with caution.