0

I have this bat file which creates folder structure in given directory path. I just want to somehow replace the path code(set /p fd= "Enter Path: ") with code that opens a dialogue in which I can select the folder. Thank you.

@echo off

set /p pr="Enter Project Name: "
set /p fd= "Enter Path: " 
MkDir "%fd%\%pr%\"
MkDir "%fd%\%pr%\%pr%_HD\"
MkDir "%fd%\%pr%\%pr%_HD\01_FILE\"
MkDir "%fd%\%pr%\%pr%_HD\02_ASSETS\"
MkDir "%fd%\%pr%\%pr%_HD\03_LOGS\"
MkDir "%fd%\%pr%\%pr%_UHD\"
MkDir "%fd%\%pr%\%pr%_UHD\01_FILE\"
MkDir "%fd%\%pr%\%pr%_UHD\02_ASSETS\"
MkDir "%fd%\%pr%\%pr%_UHD\03_LOGS\"
Maclad
  • 3
  • 1

2 Answers2

1

Here's a quick example, without explanation, as you were technically only requesting code:

0</* :
@Set "pr=test"
@Set /P "pr=Enter Project Name: "
@For /F "Delims=" %%G In ('%SystemRoot%\System32\cscript.exe //E:JScript //NoLogo "%~f0" 2^>NUL ^| %SystemRoot%\System32\find /V ""')Do @For %%H In ("HD" "UHD") Do @For %%I In ("01_FILE" "02_ASSETS" "03_LOGS") Do @MD "%%G\%pr%\%pr%_%%~H\%%~I"
@Exit /B */0;
var Folder=new ActiveXObject('Shell.Application').BrowseForFolder(0,'Select your directory.',1,'0');
try{new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(Folder.Self.Path)};catch(e){};close();

You should be aware that your code, and therefore this, does not determine whether the end user entered a string which is allowed as a directory name in Windows. I have also, pre-set a string value as test, so if your end user provides no input to the Enter Project Name prompt, it will at least create some directories for you.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • That works man as expected ..thank you! ...and also thanks for that extra line to execute with test...that helps – Maclad May 17 '21 at 17:22
  • hey @compo is it possible to get layout like this? i.stack.imgur.com/Iuvqm.png – Maclad May 17 '21 at 17:48
  • 1
    It may well be @Maclad , but as your question provided only a specification, and I've provided an answer which does that, and which you've already stated works as expected. I'm not going to write more code for you with no effort whatsoever shown by you. This is not a code to order service, and I've already gone beyond the true scope of this site for you, it is rude for you to request I do so again. – Compo May 17 '21 at 20:54
0

You can call out to Powershell if you want a GUI to pick a folder. Either of these two should work for you.

set "psCommand="(new-object -COM 'Shell.Application').BrowseForFolder(0,'Please choose your SOURCE folder.',0x010,17).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "location=%%I
echo %location%
pause

--

set "psCommand="(new-object -COM 'Shell.Application').BrowseForFolder(0,'Please choose the folder.',0,0).self.path"" 
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "folder=%%I"
echo %folder%
pause

And here is your code merged with my code. I assume you are not doing it like this because this is tested and verified.

@echo off
set /p pr="Enter Project Name: "
set "psCommand="(new-object -COM 'Shell.Application').BrowseForFolder(0,'Please choose your SOURCE folder.',0x010,17).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "fd=%%I

MkDir "%fd%\%pr%\%pr%_HD\01_FILE\"
MkDir "%fd%\%pr%\%pr%_HD\02_ASSETS\"
MkDir "%fd%\%pr%\%pr%_HD\03_LOGS\"
MkDir "%fd%\%pr%\%pr%_UHD\01_FILE\"
MkDir "%fd%\%pr%\%pr%_UHD\02_ASSETS\"
MkDir "%fd%\%pr%\%pr%_UHD\03_LOGS\"
Squashman
  • 13,649
  • 5
  • 27
  • 36
  • hey thanks for reply ...this code is making file in parent director and not in sub directory. – Maclad May 17 '21 at 17:43
  • @Maclad this code does not make a directory. It assigns the folder you picked to a variable. Use the variable it created. – Squashman May 17 '21 at 17:51
  • yeah I am using variable created but still it makes in parent directory ..e.g. I am selecting path D:\new\test\ but file is made in D:\new\ – Maclad May 17 '21 at 18:16
  • @Maclad what does the `mkdir` command looks like? – Squashman May 17 '21 at 18:30
  • I am new to this but I guess this is what you need `MkDir "%folder%%pr%\"` full bat I am using is here [ https://pastebin.com/5b1vEqNn ] – Maclad May 17 '21 at 18:38
  • @Maclad for the sake of giving you a fish, I have merged your code with the example code. – Squashman May 17 '21 at 18:42
  • this works man!!!..I was using `echo %fd%` which was wrong I think...hey is it possible to change current layout selection dialog to this https://i.stack.imgur.com/Iuvqm.png – Maclad May 17 '21 at 18:52
  • Well at some point you have to learn to fish. Maybe starting looking at how you can do that with Powershell. But just looking at the screenshot that looks like a File Selection box and not a Folder selection. – Squashman May 17 '21 at 19:00
  • I am not understanding what you mean by Learn to fish. – Maclad May 17 '21 at 19:17
  • I think @Compo and myself have done enough research and development for you. Please read the link Compo posted under his answer. My last comment was referring to the Bible. **"Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime."** – Squashman May 17 '21 at 21:14