question about BAT file creation

T

Tim.T

I have Temp folders on more than one drive, and often they get full with
files created by particular software I use; I just want to be able to check
their contents, and if neccessary remove the files therein. While I do have
some "cleaner" programs which remove temp files, they don't always do the
trick.

I'm trying to create a BAT file which will change to each Temp folder
location, and list its contents. However, no matter how I type it, it always
just shows C: drive and nothing else. This is how I type it in Notepad:

cd c:

dir /s /b *Temp

pause

cd g:

dir /s /b *Temp

pause

cd v:

dir /s /b *Temp

pause

What I don't understand is, these commands work fine if I type them in the
Command Processor window in sequence. I just can't seem to get them to work
in sequence as a BAT file. Any idea what I'm doing wrong? I'm clearly
missing an extra command/s to get the BAT to work. I want the BAT to work no
matter where it is located on my PC, too; for some reason it only lists C:
no matter where I run it from.

Tim
 
B

Bob I

Remove the "cd " from in front of the drive letters. Thusly

C:
dir /s /b *Temp
pause
G:
dir /s /b *Temp
pause
 
P

Pegasus \(MVP\)

See below.

Tim.T said:
I have Temp folders on more than one drive, and often they get full with
files created by particular software I use; I just want to be able to
check
their contents, and if neccessary remove the files therein. While I do
have
some "cleaner" programs which remove temp files, they don't always do the
trick.

I'm trying to create a BAT file which will change to each Temp folder
location, and list its contents. However, no matter how I type it, it
always
just shows C: drive and nothing else. This is how I type it in Notepad:

cd c:

*** This command does precisely nothing. If you want to make
*** drive C: your current working drive then you simply type this:
*** C: {Enter}
dir /s /b *Temp

*** I suspect you mean this command:
*** dir /s /b c:\temp{Enter}
pause

cd g:

*** G:{Enter}
dir /s /b *Temp
*** dir \temp{Enter}, or
*** dir G:\temp{Enter}
pause

cd v:

dir /s /b *Temp

pause

What I don't understand is, these commands work fine if I type them in the
Command Processor window in sequence. I just can't seem to get them to
work
in sequence as a BAT file. Any idea what I'm doing wrong? I'm clearly
missing an extra command/s to get the BAT to work. I want the BAT to work
no
matter where it is located on my PC, too; for some reason it only lists C:
no matter where I run it from.

Tim

If you want your batch file to work no matter where it is located then
you MUST specify three things:
1. The drive letter;
2. The folder name;
3. The file name.

The above commands lack two of the three things, hence they fail
most of the time.
 
D

David Webb

You don't need the cd command.

Try this version:

c:
dir /s /b *Temp
pause
g:
dir /s /b *Temp
pause
v:
dir /s /b *Temp
pause
 
T

Terry R.

The date and time was 5/23/2008 6:52 AM, and on a whim, Tim.T pounded
out on the keyboard:
I have Temp folders on more than one drive, and often they get full with
files created by particular software I use; I just want to be able to check
their contents, and if neccessary remove the files therein. While I do have
some "cleaner" programs which remove temp files, they don't always do the
trick.

I'm trying to create a BAT file which will change to each Temp folder
location, and list its contents. However, no matter how I type it, it always
just shows C: drive and nothing else. This is how I type it in Notepad:

cd c:

dir /s /b *Temp

pause

cd g:

dir /s /b *Temp

pause

cd v:

dir /s /b *Temp

pause

What I don't understand is, these commands work fine if I type them in the
Command Processor window in sequence. I just can't seem to get them to work
in sequence as a BAT file. Any idea what I'm doing wrong? I'm clearly
missing an extra command/s to get the BAT to work. I want the BAT to work no
matter where it is located on my PC, too; for some reason it only lists C:
no matter where I run it from.

Tim

Hi Tim,

CD stands for Change Directory. So, cd C: is incorrect as C: is not a
directory. I don't see how it works at a command prompt.

Try this:

c:
dir /s /b *Temp
pause

g:
dir /s /b *Temp
pause

v:
dir /s /b *Temp
pause

--
Terry R.

***Reply Note***
Anti-spam measures are included in my email address.
Delete NOSPAM from the email address after clicking Reply.
 
T

Tim.T

As soon as I posted this I figured it out. Basically I forgot to add the
drive letter before the "*Temp" bit. Thus, "dir /b /s C:\*Temp*, etc. Also I
didn't need the "CD" bits.

Tim
 
T

Terry R.

The date and time was 5/23/2008 7:20 AM, and on a whim, Tim.T pounded
out on the keyboard:
As soon as I posted this I figured it out. Basically I forgot to add the
drive letter before the "*Temp" bit. Thus, "dir /b /s C:\*Temp*, etc. Also I
didn't need the "CD" bits.

Tim

You don't need to enter the drive letter once you are already on the
drive. So if you're in drive V:, dir /s /b *Temp will list all the temp
folders in that drive.

--
Terry R.

***Reply Note***
Anti-spam measures are included in my email address.
Delete NOSPAM from the email address after clicking Reply.
 
T

Twayne

I have Temp folders on more than one drive, and often they get full
with files created by particular software I use; I just want to be
able to check their contents, and if neccessary remove the files
therein. While I do have some "cleaner" programs which remove temp
files, they don't always do the trick.

I'm trying to create a BAT file which will change to each Temp folder
location, and list its contents. However, no matter how I type it, it
always just shows C: drive and nothing else. This is how I type it in
Notepad:

cd c:

dir /s /b *Temp

pause

cd g:

dir /s /b *Temp

pause

cd v:

dir /s /b *Temp

pause

What I don't understand is, these commands work fine if I type them
in the Command Processor window in sequence. I just can't seem to get
them to work in sequence as a BAT file.

Once you have your head around them, they will <g>.

Any idea what I'm doing
wrong? I'm clearly missing an extra command/s to get the BAT to work.
I want the BAT to work no matter where it is located on my PC, too;

Then it simply needs to reside somewhere in the "Path", most logically
probably your Program Files directory/folder. Directory = Folder; same
thing.
for some reason it only lists C: no matter where I run it from.

That's because of your "CD C:" line. It has to be simply " C: " CD
only works for "Change Directory"; drives are not directories(folders).


"CD C:" does not work as you expect from the command prompt. It does
something, but not what you expect. Your following DIR will display
whatever drive you were on when you executed the CD, NOT the one on C:.
Look closer and you'll see it. Or just hit Return and you'll see you're
still on the original drive, not C.

The correct command is simply "drive:" or, C: for instance. THEN,
regardless of where you were, you will go to the drive C: root
directory.


Assuming the batch file also does the deletions, which you have not
indicated in your code above:

In addition to the other posts, I'd just like to add something I didn't
notice mentioned and directly respond to a couple points you made:
IF a particular temp file happens to be in use you can not delete
it. That's going to cause the batch file to present an error message at
delete time. You can often avoid that if you make running the batch
file the very first thing you do after a boot. Or, employ the
appropriate error catching techniques.

In order for a .bat to work "no matter where it's located on your PC",
two things are necessary:
The .bat file either:
-- MUST reside in the folder you execute it from, OR
-- The .bat file MUST be in the path. This is the best answer to your
problem rather than having several batch files spread all over the
place. A logical place to put it for produtcion use would be your
Program Files folder. Then it'll run no matter where you execute it
from. Because it's in the "path".

IF the batch file resides anywhere that is NOT in the path, then you
will also have to use fully qualified paths within the file; e.g.
c:\windows\temp...\... , which I don't think is what you want to do.

HTH

Twayne
 
T

Tim Slattery

Tim.T said:
As soon as I posted this I figured it out. Basically I forgot to add the
drive letter before the "*Temp" bit. Thus, "dir /b /s C:\*Temp*, etc. Also I
didn't need the "CD" bits.

Yes, giving the "dir" command the full path to the directory you want
it to look in will certainly work. Nobody seems to have mentioned the
/d flag in the "cd" command. That lets you change drives as well as
directories:

cd /d d:\mydir

switches to directory \mydir on drive d:.
 
J

jameshanley39

Yes, giving the "dir" command the full path to the directory you want
it to look in will certainly work. Nobody seems to have mentioned the
/d flag in the "cd" command. That lets you change drives as well as
directories:

cd /d d:\mydir

switches to directory \mydir on drive d:.

--


yes, that is a good one.. I wonder if it is just an NT thing.. Prob
not on 9X boot disk/DOS 7

DOS 6.22 didn't have it
http://www.vfrazee.com/ms-dos/6.22/help/
so that would explain why it's not so well known..

similarly, some commands like For, got more useful. for /r for
example, many are not used to. People used to use 3rd party
sweep.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top