Sanitizing filenames for code
Sandilya Bhamidipati
Posted on July 6, 2018
A lot of us must have seen this coming.SPACES IN FILENAMES. There is no escaping coz everyone does not follow sanity. However, part of an engineer/dev in you says let me fix this. There are a ton of ways on how to do that. As much as I prefer writing code to fix my problems, not everything needs code as I am firm believer in do not re-invent the wheel. Hence the following post.
The most generic pain-in-the-neck problems arise from space in filenames. I have used all possible solutions from using tr
command to using automator in MacOS. However, not all solutions are applicable across all platforms. Hence, I ended using the detox command line utility. Here is why.
[~/Downloads/tmp/temp] $ tree .
.
├── file\ name\ 1.txt
├── file\ name\ 2.txt
├── file\ name\ 3.txt
└── file\ name\ 4.txt
[~/Downloads/tmp/temp] $ detox *.txt
[~/Downloads/tmp/temp] $ tree .
.
├── file_name_1.txt
├── file_name_2.txt
├── file_name_3.txt
└── file_name_4.txt
I hope this elegant solution improves your productivity. Happy coding.
Posted on July 6, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.