Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsWindows VistaWindows XPWindows MeWindows 98Windows 95Virtual PCInternet ExplorerOutlook ExpressWindows MediaSecurity
Related Topics
MS Server ProductsMS OfficePC HardwareMore Topics ...

Windows Forum / Windows XP / General Topics 1 / May 2008

Tip: Looking for answers? Try searching our database.

question about BAT file creation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim.T - 23 May 2008 14:52 GMT
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
Bob I - 23 May 2008 15:01 GMT
Remove the "cd " from in front of the drive letters. Thusly

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

> 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
[quoted text clipped - 32 lines]
>
> Tim
Pegasus (MVP) - 23 May 2008 15:07 GMT
See below.

>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
[quoted text clipped - 10 lines]
>
> 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
>
[quoted text clipped - 14 lines]
>
> 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.
David Webb - 23 May 2008 15:12 GMT
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

>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
[quoted text clipped - 32 lines]
>
> Tim
Terry R. - 23 May 2008 15:14 GMT
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
[quoted text clipped - 32 lines]
>
> 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

Signature

Terry R.

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

Tim.T - 23 May 2008 15:20 GMT
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

> 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
[quoted text clipped - 32 lines]
>
> Tim
Terry R. - 23 May 2008 15:30 GMT
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
[quoted text clipped - 43 lines]
>>
>> 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.

Signature

Terry R.

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

Tim Slattery - 23 May 2008 17:33 GMT
>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:.

Signature

Tim Slattery
MS MVP(Shell/User)
Slattery_T@bls.gov
http://members.cox.net/slatteryt

jameshanley39@yahoo.co.uk - 23 May 2008 18:21 GMT
> >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
[quoted text clipped - 10 lines]
>
> --

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
Twayne - 23 May 2008 16:57 GMT
> 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
[quoted text clipped - 28 lines]
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.