Category Archives: Uncategorized

Deleting files exactly in windows cmd or .bat

Background

I recently needed to delete a set of files after compiling them using a .bat file script to help with a build process. The previous step in the process generated .jsxbin from jsx files. These are compiled binary versions of plain-text ExtendScript source code. I used the VSCode ExtendScript Debugger extension which has very limited capabilities. It moves recursively through a directory provides the jsxbin files in the same folder as the jsx, without deleting the jsx files. There isn’t an option to do anything different so, I deal with it.

Initial thought

I’ve been in software for quite a while and never thought this problem would be so hard. My initial thought was to use this:

del /S *.jsx

Delete recursively any file that ends in .jsx…

Wrong. It also deleted the jsxbin files. The Windows operating system has been around for a while but apparently it still doesn’t have a quick command to delete exactly what you tell it to.

This isn’t a new problem, I thought to myself. There must be an equally simple way to tell it not to delete files with an extension other than jsx.

Nope. At least, I never found it.

The Solution

So, based on what I found after reading various Stack Overflow posts, I wrote a bat file just for this purpose. It needs some modification to make it more generic but for now, it does what’s necessary.

@echo off
pushd %1
for /f "eol=: delims=" %%F in ('dir /b /s *.jsx^|findstr /lie ".jsx"') do del %%~fF
popd

That’s right. All that is to replace del /S *.jsx.

Saving that in a bat file called delext.bat, I can now enter something like

delext.bat C:\path\to\directory

and it will delete all the jsx files it finds, recursively, without deleting the jsxbin.

If I have the time, I’ll update this post to show a more generic version.

Coloring shell scripts

Adding color to shell scripts is actually quite easy. Here’s an excellent page describing how: http://misc.flogisoft.com/bash/tip_colors_and_formatting

I would add that it becomes easier if you use variables. Then, it’s almost like a css class for your terminal output. For example, if I want to make bold green success text output by one of my scripts, I might do something like this:

#!/bin/bash
SUCCESS='\033[1;32m' # Bold;Green
NC='\033[0m' # No Color
# ...commands
echo "Almost there..."
echo -e "${SUCCESS}Success!${NC}" #shows in bold green

The -e after echo enables the parsing of escape sequences. It’s important to have there.

There are a lot more ways you can use the formatting for your scripts. Explore and enjoy!

How to create a default date range for google search

Something I have been wanting a LONG time has been the ability to set my google searches to default to Past Year. Since I do a lot of software related searches, results from 5 years ago are usually irrelevant.

I did a search on the structure of google search urls and found this post: http://www.our-picks.com/archives/2007/01/30/google-search-urls-revealed-or-how-to-create-your-own-search-url/

Here’s how to set up Chrome to use the past year as your default search range:

  1. Go to settings.
  2. Under the Search heading, click the Manage Search Engines… button.
  3. Scroll to the bottom of the page, so you see the 3 fields for entering your own search engine.
  4. Put these in the three fields:
    1. GoogleYear
    2. search.google.com
    3. {google:baseURL}search?q=%s&as_qdr=y&{google:RLZ}{google:acceptedSuggestion}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}ie={inputEncoding}
  5. Click the “Make default” button that appears at the end of the row you just made.
  6. Click DONE and you’re set. Now your omnibox will always default search results to the past year unless you change it the usual way from the Search Tools at the top of the results page.

For other browsers, you can do something similar with a bookmark to the following: http://www.google.com/search?as_qdr=y or by setting up a custom search engine similarly.

Enjoy!