Click here for important information about

user input in batch file

Microsoft Windows xp home edition with s...
June 12, 2010 at 05:09:54
Specs: Windows XP, 1.60Ghz 640mb
Hi, i'm working on a program that will cleanup your computer by deleting some files, but I want the user to be able to input which files/folders to delete so far I have this:

@echo off
echo It is strongly advised that you read README.txt first.

set /p choice=What folder would you like to delete?(For more info see README.txt)
rmdir /s /q %choice%
set choice=

attib -h -s C:\RECYCLER
rd -h -s C:\RECYCLER

echo Completed, %choice% has been deleted

However it is telling me that The system cannot find the file and path specified, any help would be greatly appreciated, oh and also is there a way to allow the user to browse their files and select which one/s they want to delete?
Many thanks

See More: user input in batch file

June 12, 2010 at 09:42:03
:: recommend this in case of environmental interference
set choice=
set /p choice=What folder would you like to delete?(For more info see README.txt)
:: add quotes around
rmdir /s /q "%choice%"
set choice=

:: typo only?
::attib -h -s C:\RECYCLER
attRib -h -s C:\RECYCLER
rd -h -s C:\RECYCLER
the pause lets you try and see which command caused the error. (ie: if error occurs before or after the pause)

Report •

June 12, 2010 at 13:50:46
Your 'logic' is lost on me but a good rule of thumb is: don't mess with 'system' folders/files. RECYCLER [or RECYCLED] is one of them.

Helping others achieve escape felicity


Report •

June 12, 2010 at 13:55:26
for "browsing" you really need a gui-driven app, but i wrote this awhile back for attempting
to browse/select files into a list.

@echo off & setlocal enabledelayedexpansion
:: demonstrates a simple "menu" driven by batch & (key,top,up)
:: CONTROLS: - for up, ENTER for set and down,
:: + for down, space or bckspace clear and down, space clear only
:: esc to finish, tab to quit
If exist goto :oo
(echo e0100 BE 81 00 AC 3C 20 74 08 B4 07 CD 21 B4 4C CD 21
echo e0110 AC 3C 32 74 0E B4 03 CD 10 80 FE 01 72 0C 80 EE
echo e0120 01 EB 03 BA 00 00 B4 02 CD 10 CD 20
echo rcx
echo 2c
echo w
echo q)| debug>nul
set /a nn=0
:: tre is a tree of the "work" directory, used to generate a selection-table
tree /f c:\work > tre
for /f "skip=3 tokens=* delims=" %%a in (tre) do (
set /a nn+=1
set dd!nn!=
set zz!nn!=%%a)
:: no. of displayable lines, change as needed
set /a screen=48
set /a st=1
set /a ee=st+screen
if %ee% gtr %nn% set ee=%nn%
for /L %%a in (%st% 1 %ee%) do (
echo !dd%%a! !zz%%a!
set /p e=+,-=down,up. ENTER=set+dn. SPACE=clear. BKSP=clear+dn. F=pagefwd, B=pageback<nul
kk 2
set /a aa=st-1

:------------- MAIN LOOP
set /a aa+=1
if !aa! gtr !nn! goto :done
if !aa! geq !ee! set /a st+=screen & goto :top
set /a flag=0
set /a xx=%errorlevel%
if !xx! equ 0 set /a flag=1 & goto :nodown
IF !XX! equ 1 (
kk 2
for /L %%a in (1 1 48) do echo.
set /a aa=48
goto :nodown)
if !xx! gtr 47 goto :number
goto :!xx! 2>nul
goto :nodown

:------------- SUB LABELS
:27 :--- ESC: End, save data
goto :done
:9 :--- TAB: jumpout w/no changes recorded
goto :eof
:8 :--- BCKSPACE: clear and down1
set dd%aa%=
goto :down1
:13 :----- ENTER: set and down1
set dd%aa%=X
goto :down1
:45 :----- MINUS (-): up one
if !aa! gtr 1 (
kk u
set /a aa-=1
if !aa! lss !st! set /a st-=screen & goto :top
goto :nodown)
:43 :----- PLUS (+): down one
goto :down1
:32 :----- SPACE: clear
set dd%aa%=
kk u
goto :nodown
:46 :----- dot set: don't move
set dd%aa%=X
kk u
goto :nodown

:: F / f
if %errorlevel% equ 70 set /a st+=screen & goto :top
if %errorlevel% equ 102 set /a st+=screen & goto :top
:: B / b
if %errorlevel% equ 66 set /a st-=screen & goto :top
if %errorlevel% equ 98 set /a st-=screen & goto :top
goto :nodown

echo list to be processed:
for /L %%a in (1 1 !nn!) do (
if /i "!dd%%a!" equ "x" (
:: this removes the graphic vertical bar.
set zz%%a=!zz%%a:³=!
set zz%%a=!zz%%a:À=!
echo [!zz%%a!]
call :strip !zz%%a!
echo !list!
>output echo !list!
goto :eof

:strip : remove leading spaces
set xx="%*"
set list=%list% %xx%

Report •

Related Solutions

June 12, 2010 at 23:54:27
attrib -h -s C:\RECYCLER
rd -h -s C:\RECYCLER

-h -s new parameters for rd?

Report •

Ask Question