# Please help with bat.file



## john1 (Nov 25, 2000)

Hi,

Im trying to write a Batch file,
its job is fairly simple.
But i havent got it right yet.
If anyone can help this is its job:
*
Please take a DIR of the 'Progra~1' folder
and copy it to 'Contents.txt' which i have
put here 'C:\Windows\Progra~1\contents.txt'
thank you
*
This is my latest attempt:

DIR C:\windows\Progra~1>contents.txt


----------



## IMM (Feb 1, 2002)

That'll work if the directories exist.
I find myself wondering if you don't mean
*dir c:\progra~1 > c:\windows\contents.txt* instead tho' *Program Files* is usu. a directory off of the root.

/l for lower case
/b for bare

Type dir /? for the possible parameters.


----------



## john1 (Nov 25, 2000)

Hi IMM,

I thought it would work too,
but it doesn't work like that.
I have tried a few combinations,
but i havent got it to work yet.

I have a bat which puts the DIR listing of C:
into a file in C: which is called contents.exe

I want a similar bat to put the DIR listing of
'Program Files' into a file in 'Program Files'
which is there and i have called it contents.exe

So far i have been unable to do this.
I am most frustrated.

I will try any suggestion you put forward.

John


----------



## john1 (Nov 25, 2000)

Well i found that a bat.file seems to refer itself
to the folder that it occupies.

If you just put DIR it will return a dir list of
whatever folder it occupies.

So i have put this bat into the Program Files.
*
DIR/O>contents.txt
*
and yes, it puts a list of the program files into
the file C:\Windows\ProgramFiles\contents.txt
exactly as i want it to.

But now i want it to go away.
How do i make it go away?

I dont know that command.
And i dont know what such a command might be called.

I have to 'X' in the corner, to get rid of it.
How do i make it go away on its own ?


----------



## john1 (Nov 25, 2000)

Well i found a way.
Its probably not the right way.
this is what i put:

Shortcut in C:\Windows\StartMenu\Startup
that kicks off the bat.file in Program Files

*dir/o>contents.txt*
that writes a dir of the program files folder
into a txt file in the programs folder

*cd\*
this got tried in a flash of cranial fibrillation,
it was hoped it might refer the bat to the root.

*cls*
this got tried cos i saw it somewhere, and it
exited the application i think.

it worked.
i was quite taken back by that.

This will keep a running and up to date txt file
of my programs, every startup its re-written.

Dont know if i will keep it though,
i expected the bat to just flash and be gone,
but it lingers long enough to annoy.

Cheers, John


----------



## IMM (Feb 1, 2002)

In the properties of the shortcut you created (under the program tab) select run minimized and checkthe box for close on exit.

The /O you have is for sortorder and really doesn't mean anything w/o a second 'letter' - eg. /ON for sort by name.

cls is 'clear screen' but shouldn't close it.

cd\ will indeed change you to the root directory of the logged drive.
Perhaps easier, is to use the Properties of the shortcut to assign a 'Start In' directory.


----------



## john1 (Nov 25, 2000)

Hi IMM,

Hey thanks for that,
i never thought of looking for a tickbox!

I found the tickbox, and i will try it soon.
As to cls, i remember now, its a throwback from
my days using 'basic' on those old machines.

It does get rid of the black bat window, wether
or not that means its closed or stopped the bat
i dont know.
It doesnt appear from CTL-ALT-DEL so i guess it
actually ends the bat.

As to the dir/o, it does actually put them into
numero-alphabetic order.

However, i am now very intrigued by your suggestion
of using 'start in' from the shortcut, the shortcut
is actually in the Startup folder of Windows,
would this make its running time shorter?

Maybe if i did the changes you suggest it would run
quicker and not linger so long and annoy me.
I expected it to be so quick, that you would only
notice it if you were looking for it, just a brief
black flash.

As it is, its a few seconds, i dont like that at all.

Cheers, John


----------



## brendandonhu (Jul 8, 2002)

In case you didn't know, for "Close on Exit" to work the last line of the batch file must be
EXIT


----------



## john1 (Nov 25, 2000)

Thanks Brendan,
No i didnt know,
been fiddling with computers for years,
never got to grips with bat files.
John


----------



## brendandonhu (Jul 8, 2002)

[tsg=yourewelcome][/tsg]


----------



## IMM (Feb 1, 2002)

If you really wish to remove the background time (mostly informative screen writes) - send them to the bit-bucket
> nul
for all the screen output.

BTW - such dos apps show as WINOA386.MOD or WINOLDAP or MS-DOSPrompt or similar (depending on how you instantiate or view them)

Want me to rewrite it?

_As to the dir/o, it does actually put them into numero-alphabetic order._
Guess I learned something there - with win98 /O must default to /ON for <alphabetic> sort order if nothing follows the O . Never tempted that fate before


----------



## john1 (Nov 25, 2000)

Thank you IMM,
yes please,
i would very much like you to write it for me.

Let me be clear about what i would like.
My original intention was to include a txt file
in each of the important folders.

These to contain the dir list of each, and to be 
overwritten each startup with the fresh info.

It may be of limited use, but that was my aim.

However the bat took so long doing that for just the
program files folder, that i had just about given up.
I would not mind a quick flash of a dos window,
but lingering for long enough to read any of it is
definately not what i had in mind.

I have no idea what you are saying in that sentence:
*
If you really wish to remove the background time
(mostly informative screen writes) - send them to
the bit-bucket
> nul
for all the screen output.*

except for the last part,
where it seems you say that i can send the screen
output somewhere else.

Now i am assuming that by screen output you mean
the part that shows on the monitor,
And i am assuming that by sending it somewhere
else, that it wont appear on the monitor screen.

I may be wrong, maybe you dont mean that.

If you do mean that, then thats fine.
If it doesnt show, it can take its time.

So yes, i am most interested.
Its about time i learnt how to do this stuff!

Best regards, John


----------



## brendandonhu (Jul 8, 2002)

By bit-bucket he just means don't display it.

use > nul 
and DOS will execute the bat. file but it won't display the results on the screen.


----------



## john1 (Nov 25, 2000)

Thanks Brendan, 

i will try that, i think its called a 'direct'
Do you know what IMM meant in his BTW ?

John


----------



## brendandonhu (Jul 8, 2002)

Which part do you mean?
The bit-bucket deal?


----------



## john1 (Nov 25, 2000)

Hi,

no, i got some of that,
i meant this bit:
*
BTW - such dos apps show as WINOA386.MOD or WINOLDAP
or MS-DOSPrompt or similar (depending on how you
instantiate or view them)
*
This bit kinda left me behind ...


----------



## brendandonhu (Jul 8, 2002)

When you use
>nul
Doing alt+ctrl+del will show one of those names for your batch file when its running.


----------



## john1 (Nov 25, 2000)

Cheers Brendan,
I think i see ...

Although in this case,
i'm hoping the bat will be done
within a second or two.

John


----------



## john1 (Nov 25, 2000)

Hi Brendan,

I tried that >null
but i couldn't seem to work it from 'Startup'
CLS works ok though.
I ticked the box for close on exit,
but it didnt close,

hang on, i'll try it in the shortcut too,
that might do it ...

John


----------



## john1 (Nov 25, 2000)

that did it.
strange.
i'm gonna try removing the tick from the bat,
but leaving it in the shortcut ....


----------



## john1 (Nov 25, 2000)

well the EXIT works like that ok.
just ticked in the shortcut, but not in the bat.

Now why wont this >null work ??


----------



## john1 (Nov 25, 2000)

Ah,

i think i am spelling it rong ...

its *nul* not *null*

i have to try again now .....


----------



## john1 (Nov 25, 2000)

Still not working


----------



## brendandonhu (Jul 8, 2002)

> nul

Notice the space between > and N.


----------



## john1 (Nov 25, 2000)

right OK,
i'll try again!!

i will get there, eventually ...


----------



## john1 (Nov 25, 2000)

Still not got it right,

> nul
dir/o>contents.txt
EXIT

Its still showing a Dos window briefly.


----------

