less than 1 minute read

If you have had to create a directory structures to provide a template for other users, you can find some tricks online on how to do that. But all of those post seem to be lacking of "how to create a file in each directory in windows".

The other day I found myself with this need as I had to check a directory structure in GIT, and GIT  doesn't like you checking in empty folders.

So first I copy the directory strucuture that I wanted from somewhere else and then deleted all the files inside using:

Del /R *.* 

Well that easy I had a bunch of empty folders now to create the empty file.

Reading up on batch scripting which I have done in the past after several tries I came up with this:

@echo off

setlocal

set "location=W:\GitRepo\src\patch\ConsolidatePatch7"

for /R %location% %%G in (.) do (
Pushd %%G
echo. 2>.readme
Popd
)


That created a .readme file on each and every directory and subdirectory of location. I was then able to check in this strucutre in GIT without a problem.


Updated:

Leave a comment