Link to home
Start Free TrialLog in
Avatar of Computer Guy
Computer Guy

asked on

Batch File Question

Hi,

I have a batch file that will create a set of folders for me.

The batch file lives at D:\Check\System\Utilities

I want the folders to be created in D:\Check\System\Utilities\<folder-name>\

How can I prompt when I open the batch file to enter the folder name, then these folders will be created in <folder-name>\

md folder1
md folder2
Avatar of kyodai
kyodai

Try it like this:

FOR /F "tokens=*" %%A IN ('TYPE FOLDER NAME') DO SET INPUT=%%A
ECHO You typed: "%INPUT%"
MD "%INPUT%"
Avatar of sarabande
The batch file lives at D:\Check\System\Utilities
so far I understand what you want to do.

can you make a sample of the directory tree before, tell what the batch should ask for, a sample for the user's input and the directory tree after execution.

Sara
AIght error in the previous code, this should work:

FOR /F "tokens=*" %%A IN ('TYPE CON') DO SET INPUT=%%A
ECHO You typed: "%INPUT%"
MD "%INPUT%"
Other way to do it would be easier i think:

set /p pathName=Enter Folder name:%=%
MD %pathName%
You can get prettier if you want using GUI... this one adjusted of mine below from my script site below save as whatever.cmd or whatever.bat, it has a bit of VBScript in it which brings up a "choose a folder" box starting in the folder you set at the top.  You can either make a new folder or choose an existing then.

http://scripts.dragon-it.co.uk/links/batch-gui-folder-mk2

@echo off
Set StartPath=D:\Check\System\Utilities\

set folder=
call :getfolder
if "%folder%"=="" exit /b
pushd "%folder%
echo Folder is %cd%

REM Put your code in here, remove the above echo and Pause if wanted.

MD folder1
MD folder2

PAUSE

exit /b

:GetFolder
(echo Set objShell = CreateObject^( "Shell.Application" ^)
echo set objFolder = objShell.BrowseForFolder^( 0, "Select a folder", ^&H10^&, "%startpath%"^)
echo if objFolder is nothing then wscript.quit
echo wscript.echo objFolder.Self.Path)> "%temp%\getpath.vbs"

for /f "tokens=*" %%a in ('cscript //nologo "%temp%\getpath.vbs"') do set folder=%%a

exit /b

Open in new window


If you just want to prompt for a folder name then without showing:

http://scripts.dragon-it.co.uk/links/batch-gui-inputbox

@echo off
Set StartPath=D:\Check\System\Utilities\

set input=
call :inputbox "Please enter new folder name" "Utilities"
if "%input%"=="" exit /b
if exist "%startpath%\%input%" (
  echo That folder already exists
  pause
  exit /b
)

pushd "%startpath%\%input%"
echo Folder is %cd%
pause

REM Put your code in here, remove the above echo and Pause if wanted.
MD FOLDER1
MD FOLDER2

exit /b

:InputBox
set input=
set heading=%~2
set message=%~1
echo wscript.echo inputbox(WScript.Arguments(0),WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do set input=%%a
exit /b

Open in new window


Steve
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial