Brain Missclicks – Choose the right path

As a work-in-progress programmer, I have produced some really stupid mistakes that has taken way too long to rectify. This time, it’s file manipulation.

Messing around with some mined data, I decided to neatly modify and place it (the data) in descriptive files for more managability and control. My specification was to include in the filename, the title, source and date of extraction. Pretty easy right? Actually, yes it is. Using python, you can use the io library to open and read/write to a file in just 2 lines of code.

Error after error, the same message propped up.

File cannot be found

What?! I’m trying to create the file, it obviously won’t be found yet! Maybe it was a problem with my environment? Maybe folder permissions? Maybe I need to find an alternative way.

I eventually found some examples where someone queried the current path of the process and used os.system to touch a file of the required filename. This was looking pretty promising!

.

..

Alas… It didn’t work. 3 hours into this perculiar problem, and now I am getting bored of it. Literally, Google could help no more. Perhaps the string built name needs to escape the spaces. Went through the line of code, until I reached the date:

 %d/%m/%Y

I then proceeded to escape the formatting:

%d\/%m\/%Y

I tried again to only receive the same error. What is going on? Removed the escape slashes and that’s when it clicked.

Fundamental Linux 101

  1. Do not use ” / ” characters in Linux filenames.

What a complete noob… 4 hours of screaming, trying and crying later… it was working! Perfectly generated filenames. I won’t live this one down anytime soon!

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.