-1

I have a script

echo currentDirectory > "Folder Generator.bat"
echo for /L %%%%f in (10,-1,0) do MD Items%%%%f >> "Folder Generator.bat"

and I want it to work anywhere I put but I don't know how to make it say use the current directory in the first line

can somebody please help me out

2 Answers2

0

Use cd > "Folder Generator.bat". See the help page of cd command

>cd /?
Displays the name of or changes the current directory.
...
Type CD without parameters to display the current drive and directory.

In Windows cmd there's also a special variable named %cd% so you can use echo %cd% instead

phuclv
  • 37,963
  • 15
  • 156
  • 475
0

As an extension of the answer I provided for you in your previous question:

@(  Echo @Echo %%CD%%
    Echo @For /L %%%%G In (10 -1 0^) Do @MD Items%%%%G
) 1> "Folder Generator1.bat"

Or:

@(Echo @For /L %%%%G In (10 -1 0^) Do @MD Items%%%%G) 1> "Folder Generator1.bat"

The script will always work based on the current directory, if you haven't specifically changed it within your code. Please note however, that you cannot be sure what somebody's current directory is, when they run this command in their batch file, so should really offer them a chance to change it before creating multiple directories within it.

Additionally, if you wanted the current directory to always be that of the running batch file, you'd use CD /D "%~dp0":

@(  Echo @CD /D "%%~dp0" 
    Echo @For /L %%%%G In (10 -1 0^) Do @MD Items%%%%G
) 1> "Folder Generator1.bat"

Or stipulate it in the MD command:

@(Echo @For /L %%%%G In (10 -1 0^) Do @MD "%%~dp0Items%%%%G") 1> "Folder Generator1.bat"
Compo
  • 36,585
  • 5
  • 27
  • 39