Thursday, October 1, 2009

Sad Information Move

Well, I really want my notes to be accessible, and that means available to Spotlight more and more now, so with some sadness and some help from touch -r, I just migrated the first document from Alepin to Journler.

Alepin's export preserves the hierarchy (the way I wish the document package's internal structure did, #3 on my wishlist), but it doesn't preserve timestamps. So the package structure is flat but with the timestamps I want, and the export structure is hierarchical with a 'now' timestamp. I believe I can fix this!

cd ~/Desktop/Notes\ Exported

find . -name "*.rtf" | grep -v TXT.rtf | tee adjustTimes.txt

find . -name "*.rtfd" | tee -a adjustTimes.txt

ORIG=~/Documents/stuff/Notes.alpn

while read FILENAME; do echo "${FILENAME}"; ls -l "${FILENAME}"; BASENAME=${FILENAME##*/}; ls -ld "${ORIG}"/"${BASENAME}"*; echo; done < adjustTimes.txt

while read FILENAME; do echo "${FILENAME}"; ls -l "${FILENAME}"; BASENAME=${FILENAME##*/}; ls -ld "${ORIG}"/"${BASENAME}"*; touch -r "${ORIG}"/"${BASENAME}"* "${FILENAME}"; ls -l "${FILENAME}"; echo; done < adjustTimes.txt

rm adjustTimes.txt

Let's decompose that last long while loop. (And take out the touch command the first time you try this yourself!!! Make sure the right files show up, to make sure you won't mind the results!)

while read FILENAME; do (stuff); done < adjustTimes.txt

This is a while loop that puts the entire line, one line at a time from that text file, into the variable FILENAME. This is the iterative engine!

First, display the filename (make sure spaces come through properly escaped) with echo "${FILENAME}". Then show the directory listing with timestamp via ls -l "${FILENAME}": too new.

Since Alepin's package structure is flat, strip off everything in front the last slash; ## is greedy match removal, */ is anything before and including a slash. This should be the rtfd filename inside the Alepin document. However, rich-text-only exports from Alepin are sensibly just RTF. So to look at that timestamp, I need to convert *.rtf to *.rtfd ... or just tack on * to match zero or more characters for ls -ld ~/Documents/stuff/Notes.alpn/"${BASENAME}"*.

If all that checks out when you test it, it's time to move the Alepin timestamps to the Alepin export with touch -r ~/Documents/stuff/Notes.alpn/"${BASENAME}"* "${FILENAME}"! Admire the results with a final directory listing with updated timestamps: ls -l "${FILENAME}" (and a final echo for visual space).Ta-da!

No comments:

Post a Comment