Computing.Net > Forums > Programming > Need help with a batch file

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.

Need help with a batch file

Reply to Message Icon

Name: Devildog
Date: November 18, 2008 at 14:18:15 Pacific
OS: XP
CPU/Ram: any
Product: any
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: November 18, 2008 at 14:34:26 Pacific
Reply:


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


0

Response Number 2
Name: Devildog
Date: November 18, 2008 at 15:08:15 Pacific
Reply:

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.


0

Response Number 3
Name: BatchFreak
Date: November 18, 2008 at 16:17:39 Pacific
Reply:


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

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


0

Response Number 4
Name: Devildog
Date: November 18, 2008 at 16:56:52 Pacific
Reply:

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.


0

Response Number 5
Name: BatchFreak
Date: November 18, 2008 at 19:07:29 Pacific
Reply:

@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.


0

Related Posts

See More



Response Number 6
Name: Devildog
Date: November 18, 2008 at 19:32:30 Pacific
Reply:

It works, thanks go out to both of you.


0

Response Number 7
Name: Mechanix2Go
Date: November 18, 2008 at 22:00:17 Pacific
Reply:

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


0

Response Number 8
Name: BatchFreak
Date: November 18, 2008 at 22:14:50 Pacific
Reply:

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.


0

Response Number 9
Name: Holla
Date: November 18, 2008 at 23:43:44 Pacific
Reply:

set /p drive=Enter drive Letter:

--
Holla.


0

Response Number 10
Name: klint
Date: November 19, 2008 at 02:04:15 Pacific
Reply:

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.


0

Response Number 11
Name: Devildog
Date: November 19, 2008 at 05:27:25 Pacific
Reply:

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.


0

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 Programming Forum Home


Sponsored links

Ads by Google


Results for: Need help with a batch file

Help creating a Batch file urgent www.computing.net/answers/programming/help-creating-a-batch-file-urgent/15963.html

Need Help with DOS batch file .. www.computing.net/answers/programming/need-help-with-dos-batch-file-/12751.html

Need help with a Batch File www.computing.net/answers/programming/need-help-with-a-batch-file/14580.html