Computing.Net > Forums > Windows 95/98 > saving o/p of for-in-do command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

saving o/p of for-in-do command

Reply to Message Icon

Name: ahsabb
Date: January 30, 2007 at 23:04:27 Pacific
OS: win 98
CPU/Ram: 248MB
Product: DELL
Comment:

I am new to writing batch file.I have written a .bat file which searches for the given file

FOR %%D IN (C: D: E:) DO DIR %%D"MY FILE" /B /P /S

and now i need to save the output of this command . Since the file may be present in more than one loaction.I may get many paths and i need to sore only the first path and second path

Can i know how is this done?


Thanks in advance



Sponsored Link
Ads by Google

Response Number 1
Name: JimPIM
Date: January 31, 2007 at 07:20:50 Pacific
Reply:

Hi, In DOS type Dir /?, Enter. You will get the instructions for the directory command. I use a bat file I call Whereis.Bat it contains the following line:

Dir Path/filename /o /p /b /s

Substitute the Path and Filename you are interested in. It searches the entire drive. In a bat file Path and Filename can be %1 and %2.

You could also just try the line at the command prompt.

This may not be exactly what you want, but should get you started.

Good Luck, Jim


0

Response Number 2
Name: JimPIM
Date: January 31, 2007 at 08:49:32 Pacific
Reply:

Hi again Ashabb, My previous post is way off of what you want. I will analyze your FOR and the one in my Bat and see if I can adapt yours to work.

Jim


0

Response Number 3
Name: Mechanix2Go
Date: January 31, 2007 at 09:26:36 Pacific
Reply:

It's not obvious why you'd use /p which is 'pause' or 'page'.

I don't know how to get two lines.

This will save the output to a file:

for %%A in (s:) do dir /s/b %%A\ > filelist


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 4
Name: JimPIM
Date: January 31, 2007 at 12:45:29 Pacific
Reply:

Hi again Ahsabb,
The folowing is additions I have made to your FOR statement and batch file:

@echo off
cls

if exist anyfile.txt del anyfile.txt

for %%D in (C: D: E:) do dir %%D\%1 /b /p /o >> anyfile.txt

The @echo off and cls is to prevent some of the screen clutter when you run the bat. The if exist is to remove the old file to make way for the new one or you will just keep filling up the file. The filename to find is contained in the %1 parameter as in Whereis.bat Finename.ext. Note the new \ to make a correct path and filename. Mech is correct you really don't need the /p, but if you have Dircmd set to always page and sort you will need /-p to prevent the bat file from hanging up after each page and forcing you to keep hitting a key to get the bat to finish. I added the /o to sort the files alphabetically.

Good Luck, Jim


0

Response Number 5
Name: JimPIM
Date: February 1, 2007 at 06:25:48 Pacific
Reply:

Hi Ahsabb, I forgot to mention that I haven't solved the need for only the first two occurences of the file in a batch file. I think I would probable write that one in Qbasic or Visual Basic, count each time the file was found in each drive and end the drive access when both are in.

Jim


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows 95/98 Forum Home


Sponsored links

Ads by Google


Results for: saving o/p of for-in-do command

installing copy of win98 in dos www.computing.net/answers/windows-95/installing-copy-of-win98-in-dos/162513.html

Norton Ghost Dos Commands www.computing.net/answers/windows-95/norton-ghost-dos-commands/102288.html

Empty Recycle Bin in DOS www.computing.net/answers/windows-95/empty-recycle-bin-in-dos/64648.html