add user input to batch

March 8, 2010 at 12:03:13
Specs: Windows 7
Hi, I have a very simple batch file that creates a folder for every line in a text document

@echo off

for /f %%i in (file.txt) do mkdir %%i

is there anyway I can add to it so that it opens a browsing window first for the location of a text file with any name and then another window for the destination of where the folders are going to be created.
thanks, James.


See More: add user input to batch

Report •


#1
March 8, 2010 at 13:27:58
What, like
start .
?

Report •

#2
March 8, 2010 at 17:39:24
what do you mean 'what, like start' is that supposed to be a sugestion I know little about scripting which is why I am trying to get some help but i'm guessing adding just start isnt going to achieve what I have asked if your suggesting I use a command start then you will have to go into a bit more detail I know nothing.
thanks, James.

Report •

#3
March 8, 2010 at 17:56:04
No, I'm suggesting
start .

as in start <space> <dot>

Report •

Related Solutions

#4
March 8, 2010 at 19:11:00
ok well how do I add that to the script and there must be more to it thats not on its own going to do what I want is it?

Report •

#5
March 8, 2010 at 20:34:21
Razor's suggestion might be fair game for my comments.
The trick is to get "start ." to reflect back into the batchscript.
I do not know how to do this, but that is my own limitation.
batch-script does not support a window/gui browsing facility, although vbscript does, ( i think ). I think a batch-driven browser is not too hard to write, maybe, but i haven't made any serious effort yet. it would be a BIG script!
windows communications between GUI and batch/cmd-prompt is very very limited, and often requires "externals" such as reg.exe, debug, vbscript, etc. or other "third party" (read: *nix) utilities. Often you need to use a "squibfile" (my workd for short ascii-text communications file)
My assumption is you want to let the user "fish around" in the file system to find 1) the text file, then 2) the directory. There might be better approach, such as making textfilename as constant and offering all instances of that, (found on filesystem) and making directory as a subset of the filesystem.
sorry this long blather not much help, but your problem is genuine and possibly addressable (even using batch only).
let me know what you think, and my recommendation is to go the vbscrip route. I can try to hep with that but not good at that either!!

Report •

#6
March 9, 2010 at 02:11:47
@echo off

REM opens explorer on the current location:
explorer .

for /f %%i in (file.txt) do (
mkdir %%i
REM opens explorer in directory %%i:
explorer %%i
)


Report •

#7
March 9, 2010 at 10:34:01
Hi and thankyou to all who have replied I am afraid I know very little about programing and from your comments it seems like what I asked maybe a little more comlicated than I had thought, although a gui would have been nice what about creating a script to bring up a comand prompt window where all the user has to do is input the full path of a text file they would like to use to get the directory information hit enter then the full path of the directory they would like the folders to be created in preferably with a line of information instructing what to do, would that be a feasable/easier option?
thanks, again.

Report •

#8
March 9, 2010 at 13:12:47
here's a simple version like what you described, maybe it will help...
@echo off & setlocal
echo listfile will be used as source of names to create subfolders in a directory
set /p txtloc=enter full path to the listfile:
if not exist "%txtloc%" echo no listfile found. && goto :eof
:: (optional)
echo these directories will be created:
more "%txtloc%"
set /p dest=where do you want these to be created, enter full path:
:: optional, if you want path created: mkdir "%dest%"
pushd "%dest%" || goto :err
for /f "usebackq tokens=*" %%i in ("%txtloc%") do mkdir "%%i" && echo created directory "%%i"
goto :eof
:err
echo "%dest%" directory not found
::------ end ----

i'm going to see about a gui version possibility


Report •

#9
March 9, 2010 at 13:59:47
@nbrane

Setting to a variable named "path" is a bad idea, it will knock out access to most utilities.


Report •

#10
March 9, 2010 at 21:44:02
good point, i tend to forget these things...
maybe "empath", like the dude in star trek nex gen
thanks!

Report •

#11
March 10, 2010 at 02:33:19
Nbrane was low on coffee ... there is actually only ONE variable you may never redefine (unless done with that rare target in mind), and it is PATH !!!

But, having said that, the effects would only involve that current DOS box, so damage is limited. If you are running DOS however, I guess a boot is the best thing to do.


Report •

#12
March 10, 2010 at 05:16:34
DOSBox? No, I'm pretty sure he's using CMD, the Command Prompt.

Report •

#13
March 10, 2010 at 07:16:52
You're right, but my message was to Nbrane.

Report •

#14
March 10, 2010 at 13:18:50
Hi thanks to all who have replied especially Nbrane for the script not tried it yet but it looks like it will do exactly what I want, I'm only going to add the script to a batch file run from within widows so I neednt worry about the problems others have commented on right?
thanks, James.

Report •

#15
March 10, 2010 at 14:55:31
just be sure to rename that variable "path" into something else! i edited it out of my posted script. hope it works ok...

Report •

#16
March 10, 2010 at 15:39:46
Hi again having a few problems getting that script to work to start I couldnt get past where it asks the location of .txt until I realised instead of writing "c:\scripts\test list.txt I had to write c:\scripts\"test list.txt"
once I figured that out it listed the directorys it intends to make so I input destination directory but nothing is outputted any further ideas?
thanks.

Report •

#17
March 10, 2010 at 17:27:11
does the destination directory exist? if not, the script will eject with no errormessage. i'll fix that.
if it does exist, the second thing is there won't really be any output to screen with echo turned off. all it does is create the directories from filelist.txt. I assume you checked to see if it created them or not? let me add some verbosity:

:: optional, if you want path created: mkdir %dest%
pushd %dest% || goto :err
for /f %%i in (%txtloc%) do mkdir %%i && echo created directory %%i
goto :eof
:err
echo directory %dest% not found
::------ end --------
sorry about any mistakes i made... pls advise me of what output you get if you try it again.


Report •

#18
March 10, 2010 at 18:45:54
after input for .txt location I get list of intended created directories I then input the destination directory which exists then the screen closes and nothing is created in folder I believe there is a message comes up before the screen closes but it happens so fast I cant read it as writing this just had a thought put a line in so window doesnt close and found out it couldnt find the txt file as it was looking for "test list" as needed to input it in quotations as it has a space in title so renamed test list to list inputted without quotations and it now works.
so thats great now working perfectly big thankyou only thing would be nice to be able to input a .txt file with spaces in title is this at all possible?
thanks.

Report •

#19
March 10, 2010 at 19:17:51
yeaaaaah (whine, i HATE spaces in filenames, but ok...)
put quotes around it. also i should have put the tokens clause:
for /f "usebackq tokens=*" %%i in ("%txtloc%") do mkdir "%%i" && echo created directory "%%i"
goto :eof

should fix it, i think (not tested)
just put the quotes on the %%i after MKDIR, not the first one. ps: edited response #8 to reflect changes.
hope it works!


Report •

#20
March 11, 2010 at 16:50:22
thanks again nbrane thats well and truly sorted it for me thanks for your help.

Report •


Ask Question