Using .gitignore to ignore everything but specific directories

Here’s how I did it – you essentially have to walk up the paths, you can’t wildcard more than one level in any direction: # Ignore everything: * # Except for the themes directories: !wordpress/ !wordpress/*/ !wordpress/*/wp-content/ !wordpress/*/wp-content/themes/ !wordpress/*/wp-content/themes/* !wordpress/*/wp-content/themes/*/* !wordpress/*/wp-content/themes/*/*/* !wordpress/*/wp-content/themes/*/*/*/* !wordpress/*/wp-content/themes/*/*/*/*/* Notice how you have to explicitly allow content for each level you … Read more

How can I make PowerShell handle [ or ] in file name well?

Indeed, use of the -LiteralPath parameter is the best solution (in PowerShell [Core] v6+, you can shorten to -lp): $content = Get-Content -LiteralPath $i.Fullname -LiteralPath ensures that $i.Fullname is taken verbatim (literally); that is, [ and ] in the path are interpreted as themselves rather than having special meaning (see below). As for what you … Read more

php glob – scan in subfolders for a file

There are 2 ways. Use glob to do recursive search: <?php // Does not support flag GLOB_BRACE function rglob($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern).’/*’, GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { $files = array_merge( [], …[$files, rglob($dir . “/” . basename($pattern), $flags)] ); return $files; } // usage: to find the test.zip file … Read more