directory

How to move/rename files in Scala alvin November 11, 2018 - 8:00pm

If you ever need to move a file in Scala, I can confirm that this approach works:

Scala: How to list files and directories under a directory alvin August 15, 2018 - 10:50am

When using Scala, if you ever need to list the subdirectories in a directory, or the files under a directory, I hope this example is helpful:

import java.io.File

object FileTests extends App {

    // list only the folders directly under this directory (does not recurse)
    val folders: Array[File] = (new File("/Users/al"))
        .listFiles
        .filter(_.isDirectory)  //isFile to find files
    folders.foreach(println)

}

If it helps to see it, a longer version of that solution looks like this:

A big collection of Unix/Linux ‘find’ command examples

Linux/Unix FAQ: Can you share some Linux find command examples?

Sure. The Unix/Linux find command is very powerful. It can search the entire filesystem to find files and directories according to the search criteria you specify. Besides using the find command to locate files, you can also execute other Linux commands (grep, mv, rm, etc.) on the files and directories you find, which makes find extremely powerful. 

A large collection of Unix/Linux ‘grep’ command examples

Linux grep commands FAQ: Can you share some Linux/Unix grep command examples?

Sure. The name grep means "general regular expression parser", but you can think of the grep command as a "search" command for Unix and Linux systems: it's used to search for text strings and more-complicated "regular expressions" within one or more files.

I think it's easiest to learn how to use the grep command by showing examples, so let's dive right in.

Unix find command: How to move a group of files into the current directory alvin May 16, 2018 - 9:51pm

I just bought a bunch of MP3 music files from Amazon, and when I downloaded the zip file they provide onto my Mac, it was a bunch of files in a bunch of subdirectories; not really convenient to work with when you’re trying to import them into iTunes. So I used this Unix find command to move all of the music files from the subdirectories they were scattered in into the root directory that was created when I expanded the zip file:

cd Amazon-Music-Folder
find . -type f -exec mv {} . \;

If you ever need to either copy or move a bunch of files with a single command, I hope this example shows the correct find command syntax for your needs. (If you need to copy the files, use the cp command instead of the mv command.)

LibGDX error: Your Android SDK path doesn’t contain an SDK alvin December 25, 2017 - 5:59pm

I don’t know much about LibGDX yet, but one thing I’ve learned is that if you get the LibGDX error message, “Your Android SDK path doesn’t contain an SDK,” it’s because the LibGDX setup tool doesn’t work automatically with the Android SDK tools that you download from the Android website, at least not the default tools. (That directory may work after you do some configuration with the sdkmanager, dunno.)

A Linux shell script to rename files with a counter and copy them alvin July 11, 2017 - 8:51am

As a brief note today, I was recently looking for all Messages/iMessage files that are stored on my Mac, and I used this shell script to copy all of those files — many of which have the same name — into a directory named tmpdir, giving them all new names during the copy process:

count=1
for i in `cat myfiles`
do
    fname=`basename $i`
    cp $i tmpdir/${count}-${fname}
    count=`expr $count + 1`
done

How to search multiple jar files for a string or pattern (shell script)

Here’s a Unix shell script that I use to search Java Jar files for any type of string pattern. You can use it to search for the name of a class, the name of a package, or any other string/pattern that will show up if you manually ran jar tvf on each jar file. The advantage of this script — if you’re a Unix, Linux, or Cygwin user — is that it will search through all jar files in the current directory:

How to get Java/Scala system environment variables and properties alvin July 31, 2016 - 9:32am

Want to get the system environment variables and/or properties from your Scala or Java application? This quick post shows what environment variables and properties are available.

Here’s a little Scala application that prints all the environment variables and properties. You’ll see that you can convert it to Java very easily:

How to create an SBT project directory structure with a shell script alvin June 21, 2015 - 11:01am

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 18.1, “How to create an SBT project directory structure.”

Problem

SBT doesn’t include a command to create a new project, and you’d like to quickly and easily create the directory structure for a new project.

Solution

Use either a shell script or a tool like Giter8 to create your project’s directory structure. Both approaches are shown here.