0

I have a question on creating a batch script. I want to get the folder name as a variable in inside a path. For example:

I have a path, E:\ and there is several folders, i.e., E:\folderA, E:\folderB.

Could anyone tell me how to run a for loop and set the name of the two folders, folderA and folderB, inside a variable in a for loop using batch file?

Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
Allen
  • 53
  • 1
  • 8
  • If you already know the names of the folders why don't you just hard code them as variables? – Squashman Jan 21 '16 at 19:23
  • @Squashman likely OP mixed up i.e. and eg. Allen, is it always two folders, or the first two, or zero or more? do you want a list of them in one variable, or one variable per folder? Do you have powershell available, or would it need to be in "plain cmd"? – Cee McSharpface Jan 21 '16 at 19:36
  • this might get you going: [similar problem](http://stackoverflow.com/questions/19540089/how-to-get-the-list-of-filenames-in-a-directory-and-store-that-in-a-variable-usi) – Cee McSharpface Jan 21 '16 at 19:38
  • i am going to use plain cmd now. Since there will be multiple folders (ie, more than 2) and I have no control of the folder name (ie, I would not know the name). I want to set the folder name in a variable so that I can edit the folder one by one (like renaming, etc.). – Allen Jan 21 '16 at 19:45
  • 2
    I guess you are looking for `for /D %I in ("E:\") do echo %~nxI` -- right? – aschipfl Jan 21 '16 at 20:14

0 Answers0