Help - Search - Members - Calendar
Full Version: Selecting a file with a batch file
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
Jman1993
I am currently trying to make a batch file to backup my settings, and I have needed this option for awhile, but I've never been able to find out how to do this... I've seen it done with VBS, bu I have no idea how it was done...

I would like to have a popup box ask to select a file.... Then, I would like to have the box take the selected file (EG C:\program files\my program\myexe.exe) and do something like this inside my batch file...

CODE
set program=C:\program files\my program\myexe.exe


that way, I could later do this...

CODE
copy "%PROGRAM%" "%SYSTEMDRIVE%\backup"


Along with being able to select an individual file, I would also like to be able to select directories...

Thank you in advance...
Yzöwl
You cannot directly create a popup per say, but you can get the batch file to ask you the question and wait for a reply.

Here's a basic example with no error trapping at all.

CODE
@Echo off&Setlocal enableextensions
Set/p "PROGRAM=Select a file: "
Copy "%PROGRAM%" "%SYSTEMDRIVE%\backup"
jaclaz
QUOTE (Jman1993 @ Aug 23 2008, 03:52 AM) *
I would like to have a popup box ask to select a file....


You can use a third party app.

For a simple "file asking", check wfile :
http://home.mnet-online.de/horst.muc/w32dial.htm#wfile

For a complete pseudo GUI I recommend Wizard's Apprentice:
http://wizapp.sourceforge.net/

You can do fairly complex things with it in batxh, see this example:
http://home.graffiti.net/jaclaz:graffiti.n...ts/VDM/vdm.html

jaclaz
Jman1993
@Yzöwl

That is how I currently do it... But, I then found a batch program called "Firefox addon maker" and it would popup a folder selection window! I just had to have that! I studied the batch and the vbs for almost an hour and got nowhere.... So I really got frustrated...

@jaclaz

This program seems like it would work... But here's what keeps happening...


CODE
C:\>Wfolder CD "%SYSTEMDRIVE%" "Select your folder"
cd "C:\Program Files"

C:\>


It says it changes the dir to "C:\program files", but for some reason it doesnt...

The same happens when trying to set variables...

ANy ideas?
jaclaz
Well, if you do not call temp.bat it would be tough for it to work. whistling.gif

Try this:
CODE
Wfolder CD %SYSTEMDRIVE% "Change Directory" > temp.bat
call temp.bat


jaclaz
Jman1993
QUOTE (jaclaz @ Aug 23 2008, 09:13 AM) *
Well, if you do not call temp.bat it would be tough for it to work. whistling.gif

Try this:
CODE
Wfolder CD %SYSTEMDRIVE% "Change Directory" > temp.bat
call temp.bat


jaclaz


AWESOME! It works! I can select files, dirs, and there are some other cool apps on that site... Thanks A LOT thumbup.gif
jaclaz
QUOTE (Jman1993 @ Aug 23 2008, 04:53 PM) *
AWESOME! It works!

Sure it does newwink.gif, did you actually doubt it? woot.gif

Now, let's get rid of the temp file (2K/XP/2003 and possibly Vista, NOT 9x/Me:
CODE
@ECHO OFF
FOR /F "tokens=1,* delims= " %%A in ('Wfolder CD %SYSTEMDRIVE% "Change Directory"') do %%A>nul&cd %%B>nul


The board parses long lines strangely, the above is just TWO lines, first one is:
CODE
@ECHO OFF

and all the rest is the second one.

jaclaz
Jman1993
Thank you again! I'm currently tweaking my backup batch program thumbup.gif
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.