Batch file to get folder structure into a dynamic menu structure...

Hello,

what I would like is a batch file that will get the folder structure of the drive into a menu structure so that you can select the folder you want to go into, and once you select a folder from the menu, the subfolders of that folder would then be listed in a menu as well, and so on and so forth as deep into the folder structure as you want to drill down to. And in each menu would have a "backup current folder level" and a "list all contents of current folder" and if possible include a "go to previous folder" option.

 Basically I would like to run the batch file and be given a menu of the folders only of the c drive, then be given an option to either backup the current folder, list the files of the current folder in case I wanna to only backup one file from that folder, or select a subfolder and then be given the same options with the addition of the go to previous folder option for subfolders.

 I've tried and tried to write something like this but I'm not a strong batch script writer and just can't get anywhere with it.

 Thank you very much in advance for your help,
Ryan
Ryan BennettAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
Pure BAT scripting is not the tool to do what you mentioned.  VBS or Powershell could, but I sometimes leverage one of the clever utilities from a freeware author for this.  He has some useful tools that are not complicated but meet a need.  Take a look at:

http://www.horstmuc.de/w32dial.htm#wfolder

You could execute this from a BAT script very easily to allow the type of drill down you mention, and then when a folder is selected and you get back to the BAT script you prompt for what action is desired, if any, like backup.

There is also a file picker.

Just a thought, in case you are tied to BAT and it's useful...


»bp
0
 
it_saigeDeveloperCommented:
You would probably be better off writing something in powershell.  That being said, is this purely for learning purposes because Windows already has an Explorer.

-saige-
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
if you run
 dir /s /ad /b x:\ > AllDirsOnDrive.txt

Open in new window


You should get a list of all directories (and only directories) on the drive output to a text file AllDirsOnDrive.txt (no need for batch file).

Where x is the drive letter you want the list for.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Ryan BennettAuthor Commented:
I guess I don't explain myself very well sometimes, I'm sorry.

 I have a backup script that I use to backup the user profiles on a windows machine which lists the user profiles into a menu to choose from. Many times I find that I've miss a folder or a file here and there that is outside the user's profile and have to go back to the machine and manually grab the missed data. So I just wanted to see if I could add an option for that into the script that I have that would allow me to grab the folders or files that I want to select.

 I realize that Windows has an Explorer, but after me trying to figure out how to do it on my own and failing I really wanted to see if it was possible and so I thought I'd reach out for some help. Isn't that what this site is all about? It use to be.
0
 
it_saigeDeveloperCommented:
Don't get me wrong.  This site still is very much about helping people but sometimes without more context (which you have provided in your follow-up) it's hard to gauge whether someone is trying to re-invent the wheel or solve a problem.  In any case, as I had stated, Powershell would probably be a better alternative.  You have full .NET support which open up a whole new world of potential solutions.

-saige-
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Another thing to keep in mind is that the question asked isn't always the right one.  And the answers sometimes provided - especially by experienced professionals - may be completely different from what you expected because we have an understanding of the technologies and best practices in areas you may not.  

I read your question to indicate you wanted to create a menu out of a directory structure.  I assumed you were going to pull in a text file with a list of folders and parse them in some program you wanted to use - hence my suggestion.

But sometimes, while you may have asked for a batch file, it may not be the best solution and others who know this may provide alternate, what they perceive as better solutions.  When you participate in the dialog (as you are doing), we may discover that the "better" solutions we propose aren't feasible for one reason or another.  But until we know that, we may not focus on exactly what you asked for.  COMMUNICATION is key.
0
 
Ryan BennettAuthor Commented:
Thanks Bill I like that option looks like that might be a good alternative to what I am trying to accomplish, I'll play with it and see what I can come up with.

saige and Lee, I appreciate what you  guys are saying and will try to be as thorough as I can and keep an open mind to your suggestions. And I apologize for whipping out the pouty pants card so fast....

What I have been trying in my script is to create an array by first passing the root of the system drive to the label that builds the array:
set folder=%1
set options=
set count=0
set "choice_options="
for /F "delims=" %%A in ('dir /a:d /b %folder%') do (
    set /a count+=1
    set "options[!count!]=%%A"
    set choice_options=!choice_options!!count!
)

Open in new window


and then spitting the menu out...
for /L %%A in (1,1,!count!) do echo  [%%A]. !options[%%A]!.

Open in new window


I get the first level of folders fine, but if I try to re-use the array from another function or label to drill down lower I get an empty menu or garbage.

maybe it is a pipe dream and I need to try something else, I'm open to powershell. I've been trying to get into it a little but fall back into what little I know of batch scripting so I haven't much experience with it at all.
0
 
Ryan BennettAuthor Commented:
Thanks Bill, this will get me what I am needing.
0
 
Bill PrewCommented:
Welcome, glad that was helpful.


»bp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.