Articles

Need help with a batch file

any
November 18, 2008 at 14:18:15
Specs: XP, any

I'm trying to create a batch file that will ask a user for a drive letter and then it will run 2-3 commands on the specified drive. I can't figure out how to ask a user for a variable, and then change to the drive that they specify. Any help would be appreciated.

See More: Need help with a batch file

Report •


#1
November 18, 2008 at 14:34:26


@echo off & setlocal
:LOOP
set /P myDrive=Enter Drive letter (e.g. F:)^>
%myDrive% 2>nul || echo.Invalid Unit - Re-enter & goto :LOOP


Report •

#2
November 18, 2008 at 15:08:15

How would I incorporate this into my batch file? For example, how would I have it perform a DIR command on the drive letter specified?
Thank you for responding so quickly to my original post.

Report •

#3
November 18, 2008 at 16:17:39


SET /p drive= What drive (e.g. F:)
%drive%
DIR

I only Batch if possible, 2000 more lines of code, oh well.


Report •

Related Solutions

#4
November 18, 2008 at 16:56:52

One final thing, what I'm trying to do is to have it delete one folder named RECYCLER, and one file named autorun.inf from the drive specified. Here is my code:

SET /p drive= What drive (e.g. F:)
%drive%
dir/w/o/a/p
echo This will remove the RECYCLER folder and the Autorun.inf @
pause
attrib -h -r -s -a *.*
rmdir [RECYCLER] /s /q
del autorun.inf
echo Files removed! The program will close when you press the spacebar. @
pause

And here is the output:


C:\Users\Owner\Desktop>SET /p drive= What drive (e.g. F:)
What drive (e.g. F:)I:

C:\Users\Owner\Desktop>I:

I:\>dir/w/o/a/p
Volume in drive I is CRAIG(8GB)
Volume Serial Number is 680D-E175

Directory of I:\

[Applications] [Documents] [Drivers]
[Game stuff] [Info, Notes] [Manuals]
[Music] [PortableApps] [Projects]
[RECYCLER] [SCHOOL] [snapshot]
autorun.inf BOOTEX.LOG StartPortableApps.exe
3 File(s) 90,914 bytes
12 Dir(s) 5,823,725,568 bytes free

I:\>echo This will remove the RECYCLER folder and the Autorun.inf @
This will remove the RECYCLER folder and the Autorun.inf @

I:\>pause
Press any key to continue . . .

I:\>attrib -h -r -s -a *.*

I:\>rmdir [RECYCLER] /s /q
The system cannot find the file specified.

I:\>del autorun.inf

I:\>echo Files removed! The program will close when you press the spacebar. @
Files removed! The program will close when you press the spacebar. @

I:\>pause
Press any key to continue . . .

As you can see the rmdir and del commands ain't working and it also repeats the comments to the user, where it only needs to put them on screen once.Plus, if it wouldn't show all of the commands on screen, just the Dir command should be shown. Can you tell me what I'm screwing up? Thanks for the help.


Report •

#5
November 18, 2008 at 19:07:29

@echo off
SET /p drive= What drive (e.g. F:)
%drive%
dir /w /o /a /p
echo This will remove the RECYCLER folder and the Autorun.inf
pause
attrib -h -r -s -a *.*
RD /s /q [RECYCLER]
DEL /q autorun.inf
echo Files removed! The program will close when you press the spacebar.
pause

there that should work, your command syntax was wrong, the switches go before the file the command is being useded on. Also I find it works better when there are spaces between the switches.

I only Batch if possible, 2000 more lines of code, oh well.


Report •

#6
November 18, 2008 at 19:32:30

It works, thanks go out to both of you.

Report •

#7
November 18, 2008 at 22:00:17

The obvious:

There probably is no directory named [RECYCLER].

The not so obvious:

Probably a bad idea to delete RECYCLER since winders expects it to be there.

Not much point in putting out a msg that blabla was deleted if iy realy wasn't.


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

M2


Report •

#8
November 18, 2008 at 22:14:50

Not my fault, just helping him do what he wants.... Although I was wondering why he was doing that....


He is probably trying to make it so it will clean up these (what he sees as) unneded files/ folders. Just my observations.

I only Batch if possible, 2000 more lines of code, oh well.


Report •

#9
November 18, 2008 at 23:43:44

set /p drive=Enter drive Letter:

--
Holla.


Report •

#10
November 19, 2008 at 02:04:15

Probably the best way to remove RECYCLER is not to create it in the first place!

Right-click on your Recycle Bin icon, and then choose to use it on individual drives independently, and tell it not to use the recycle bin on any drives other than C:.

Oh and by the way, the original DEL command did work, it was just the RD /S /Q command that didn't.


Report •

#11
November 19, 2008 at 05:27:25

the problem is that it is actually a virus that creates the two files. At my college, a virus is on numerous computers, and one of the thing that the virus does is place those files on any flash drives inserted into the PC.

I won't even go into the whole argument about the college's use of crappy anti-virus that couldn't find a threat if it was staring one in the face. But I need to use the school's computers to complete some of my school work.

So the only thing left for me to do is to use a spare flash drive to do my schoolwork on, and remove those files after I am finished with my work.


Report •


Ask Question