Properly escaping spaces in filenames

Hi. I’m struggling to get ‘import from the CSV rules file’ working and I’ve tracked it down to file names. I hope someone can help me get over the final hurdle.

I’m running hledger version 1.32.3, linux-x86_64 (Linux Mint Debian Edition 13)

The bank download is Project Income.CSV containing four new transactions

my rules file is pi.csv.rules

Attempt 1:

$ hledger import ~/Downloads/Project\ Income.CSV --rules-file=pi.csv.rules --dry

; no new transactions found in “home/marko/Downloads/Project Income.CSV”

Attempt 2:

$ hledger import '~/Downloads/Project Income.CSV' --rules-file=pi.csv.rules --dry

The hledger journal file "~/Downloads/Project Income.CSV" was not found.
Please create it first, eg with "hledger add" or a text editor.
Or, specify an existing journal file with -f or LEDGER_FILE.

Attempt 3

$ hledger import ~/Downloads/'Project Income.CSV' --rules-file=pi.csv.rules --dry

; no new transactions found in "/home/marko/Downloads/Project Income.CSV"

Attempt 4 (sanity check!)

  • rename bank file to Project-Income.CSV
$ hledger import ~/Downloads/Project-Income.CSV --rules-file=pi.csv.rules --dry

; would import 4 new transactions from /home/marko/Downloads/Project-Income.CSV:
...

And using source ~/Downloads/Project-Income*.CSV in the rules file lets me run what I ultimately want:

$ hledger import pi.csv.rules --dry

; would import 4 new transactions from pi.csv.rules:
...

I can’t find anything in the hledger docs about parsing filenames, so I’m really stumped. I know I can pre-process the CSV file and rename it, but I assume I am making a beginner error somewhere! :slight_smile:

These should work. I haven't been able to reproduce your findings exactly, but I did see this strangeness in 1.32.3 and 1.34:

$ hledger-1.32.3 print -f 'a a.csv' --rules a.csv.rules  # lists commands instead of printing
$ hledger-1.40 print -f 'a a.csv' --rules a.csv.rules  # reads a a.csv as expected

I didn't find anything about spaced filenames in release notes, but 1.40 overhauled command line parsing. Can you upgrade to a newer version ?

PS and if you use a csv source rule: don't enclose the file path in quotes, and remember a bare file name is searched for in ~/Downloads (so prepend ./ if reading a file in the current directory).

PPS you might also be getting confused by import's Overlap detection, which is affected by the presence of .latest.FILENAME files. Using print for testing will avoid that complication.

Thanks Simon. I'll try upgrading first and will circle back here with a report once I have this figured out. :slight_smile:

I've been staying on top of the .latest.FILENAME files. I'll double check my source declarations too.

The upgrade did the trick. @simonmic

running version 1.51.2, source Project Income.CSV in the rules file finds the correct csv file.

I got to learn about installing outside a package manager too. And now I can use archive option when I import from csv. So win-win-win.

Thanks for your help. :sparkling_heart:

2 Likes