Get file name and extension in Ruby

You can use the following functions for your purpose: path = “/path/to/xyz.mp4” File.basename(path) # => “xyz.mp4” File.extname(path) # => “.mp4” File.basename(path, “.mp4”) # => “xyz” File.basename(path, “.*”) # => “xyz” File.dirname(path) # => “/path/to”

In Clojure 1.3, How to read and write a file

Assuming we’re only doing text files here and not some crazy binary stuff. Number 1: how to read an entire file into memory. (slurp “/tmp/test.txt”) Not recommended when it is a really big file. Number 2: how to read a file line by line. (use ‘clojure.java.io) (with-open [rdr (reader “/tmp/test.txt”)] (doseq [line (line-seq rdr)] (println … Read more

Get file name from URL

Instead of reinventing the wheel, how about using Apache commons-io: import org.apache.commons.io.FilenameUtils; public class FilenameUtilTest { public static void main(String[] args) throws Exception { URL url = new URL(“http://www.example.com/some/path/to/a/file.xml?foo=bar#test”); System.out.println(FilenameUtils.getBaseName(url.getPath())); // -> file System.out.println(FilenameUtils.getExtension(url.getPath())); // -> xml System.out.println(FilenameUtils.getName(url.getPath())); // -> file.xml } }

Get file version in PowerShell

Since PowerShell 5 in Windows 10, you can look at FileVersionRaw (or ProductVersionRaw) on the output of Get-Item or Get-ChildItem, like this: (Get-Item C:\Windows\System32\Lsasrv.dll).VersionInfo.FileVersionRaw It’s actually the same ScriptProperty from my Update-TypeData in the original answer below, but built-in now. In PowerShell 4, you could get the FileVersionInfo from Get-Item or Get-ChildItem, but it would … Read more

Record file copy operation with Git

Git does not do rename tracking nor copy tracking, which means it doesn’t record renames or copies. What it does instead is rename and copy detection. You can request rename detection in git diff (and git show) by using the -M option, you can request additional copy detection in changed files by using the -C … Read more

Java NIO FileChannel versus FileOutputstream performance / usefulness

My experience with larger files sizes has been that java.nio is faster than java.io. Solidly faster. Like in the >250% range. That said, I am eliminating obvious bottlenecks, which I suggest your micro-benchmark might suffer from. Potential areas for investigating: The buffer size. The algorithm you basically have is copy from disk to buffer copy … Read more