DEV Community

Sandilya Bhamidipati
Sandilya Bhamidipati

Posted on

7 4

Sanitizing filenames for code

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
Enter fullscreen mode Exit fullscreen mode

I hope this elegant solution improves your productivity. Happy coding.

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (1)

Collapse
 
elmuerte profile image
Michiel Hendriks • Edited

Why not "sanitizing code for filenames"?

Rule number ☃: do not trust user input.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay