Computing.Net > Forums > Programming > Batch file drive loop

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.

Batch file drive loop

Reply to Message Icon

Name: N3oblaster
Date: April 6, 2009 at 07:00:21 Pacific
OS: DOS
Subcategory: Batch
Comment:

hi i'm making a batch file that detects HDD partitions and deletes some directory's.
but i'm stuck using the loop cant realy find out how to make it work.
any help would be appreciated.


:the Batch
:CDRIVE
CLS
FOR %%P IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%P:\nul echo. %%P is aangesloten
ECHO.
ECHO ------------------------------------------------------------------------
FOR %%P IN (C) DO IF NOT EXIST %%P:\nul GOTO DDRIVE
FOR %%P IN (C) DO IF EXIST %%P:\nul echo. Wilt u naar %%P gaan?
set station={j,n}
set /p station= ja of nee (j/n):
IF '%station%'=='J' GOTO CROOT
IF '%station%'=='j' GOTO CROOT
IF '%station%'=='N' GOTO DDRIVE
IF '%station%'=='n' GOTO DDRIVE

if anyone could tell me at least how to loop this so that it goes to the drive where the yes falls



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: April 6, 2009 at 08:56:43 Pacific
Reply:

First of all post your actual operating system, as DOS is NOT the environment you are running; you run under Windows 2K/XP as the set /P statement reveals. What you believe to be DOS is the NTVDM emulator and your statements are interpreted by cmd.exe NOT command.com: in one word your script is NT batch.

So stated the code you posted may be rearranged so

:: The Batch
@echo off & setlocal EnableDelayedExpansion
CLS
FOR %%P IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
  IF EXIST %%P:\nul (
    echo. %%P is aangesloten
    ECHO.
    ECHO ----------------------------------------- 
    echo. Wilt u naar %%P gaan?
    set station={j,n}
    set /P station= ja of nee (j/n): 
    IF  /I "!station!"=="J"  (
       echo.  Response is JA
       echo. Here add your code
    )
  )
)

Type e.g. set /? or If /? to get a short on-line help. Another tip. please post ONLY in English (the text in the script body too) as this is the only language allowed in Computing.net Forum.


0

Response Number 2
Name: N3oblaster
Date: April 6, 2009 at 11:13:23 Pacific
Reply:

wel it has to run under dos 2 have to point out some flaws yet

and sry to tell but this batch doesnt really run yet trying to make it run


0

Response Number 3
Name: IVO
Date: April 6, 2009 at 13:25:45 Pacific
Reply:

My script is NT batch and requires Windows XP/2K to run. If you need a plain DOS batch you have to give up the SET /P statement as it is supported in FreeDOS but NOT in MS-DOS.

There is a workaround and I can give you the required code in pure DOS, but I need you confirm to me you have to run in real DOS environment.


0

Response Number 4
Name: lee123abc
Date: April 7, 2009 at 05:11:08 Pacific
Reply:

Mate, a good start would be to type 'ver' which is short for version into your command prompt... post the results here and the pros will be able to help you!

ciao


0

Response Number 5
Name: N3oblaster
Date: April 7, 2009 at 07:00:53 Pacific
Reply:

it has to run under XP but under DOS to
version of my PC is 5.1.2600


0

Related Posts

See More



Response Number 6
Name: Razor2.3
Date: April 7, 2009 at 07:06:14 Pacific
Reply:

N3oblaster: it has to run under XP but under DOS
These are mutually exclusive, unless you have some 20 year old PCs around.


0

Response Number 7
Name: lee123abc
Date: April 7, 2009 at 09:48:27 Pacific
Reply:

I feel sorry for the pros!


0

Response Number 8
Name: N3oblaster
Date: April 8, 2009 at 01:40:25 Pacific
Reply:

I think there's a bit of confusion in this area now let me explain it as good as i can.

the batch i am making must be able run under XP and DOS.
Why ??
Because someone has a xp machine standing which is being modified so that it can run DOS Commands, so my job for him was to make a batchfile that can run under DOS & XP to select a drive and execute the commands that are already done.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Parse first/last characte... Creating a filename from ...



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: Batch file drive loop

Batch file FOR LOOP www.computing.net/answers/programming/batch-file-for-loop/11504.html

Batch files: FOR loop counting www.computing.net/answers/programming/batch-files-for-loop-counting/20344.html

Batch file help www.computing.net/answers/programming/batch-file-help/12261.html