Reputation: 21
I'm trying to figure out how to make a batch file to create a folder+subfolder in an entire directory of individual folders.
Initially I was just asked to make a batch file to create a folder + subfolder if it did not exist, I assumed my boss would have this run on startup and came up with the following after reading around on SO for a while.
@echo off
@break off
@title Create Folder with Batch
setlocal EnableDelayedExpansion
if not exist "H:\minecraftedu\saves\" (
mkdir "H:\minecraftedu\saves\"
if "!errorlevel!" EQU "0" (
echo Folder created successfully
) else (
echo Error while creating folder
)
) else (
echo Folder already exists
)
pause
exit
However what was actually needed was to make a command that we could run from the server to create
\\server\home\Students\2018(every folder in here)\minecraftedu\saves
as well as
\\server\home\Students\2019(every folder in here)\minecraftedu\saves
Which I have no idea how to do, or if that is even possible with a batch file. The end goal is to have the students Minecraftedu worlds save to their server space instead of locally, which my plan was to use symlink to have it target the folder on the server for whichever user was logged in.
I'm on staff for my hardware abilities and programming kind of escapes me past incredibly basic stuff, so any help is appreciated!
Upvotes: 1
Views: 92
Reputation: 21
I ended up going with this which worked out, just dug around SO and online to come up with the solution.
pushd \\targetdirectory\
for /D %%G in (*) DO mkdir %%G\minecraftedu\saves
pause
Pause is just in there so I could read over while I screwed up to see how badly I did in fact screw up.
But it all worked out.
Upvotes: 1
Reputation:
Try this
@echo off
SET "basepath=h:\"
SET "structure=\minecraftedu\saves"
for /f "delims=" %%D in ('dir /a:d /b %basepath%') do (
echo creating "%basepath%%%D%structure%"
mkdir "%basepath%%%D%structure%"
)
This will create the folder structure defined in %structure%
for each subfolder directly beneath %basepath%
, it is not recursive.
Keep an eye on the \'s as forgetting one can create a mess!
Upvotes: 0