Re: question about BAT file creation
- From: "Twayne" <nobody@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 23 May 2008 11:57:40 -0400
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).
Tim
"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
.
- References:
- question about BAT file creation
- From: Tim.T
- question about BAT file creation
- Prev by Date: Re: XP 64 OEM
- Next by Date: Re: How to reboot computer to facry settings?
- Previous by thread: Re: question about BAT file creation
- Next by thread: Installing fonts non-admin
- Index(es):
Relevant Pages
|