Page 1 of 1

Spaces in filenames

Posted: Sun Sep 10, 2017 6:34 pm
by aangel
I use Keka as the front end but also am setting up a regular backup of a folder on my iCloud drive via the cli.

I want this is a script so that it's more legible and I can parameterize it later. The beginning of script so far is:

Code: Select all

SOURCE_DIR=~/Library/Mobile\ Documents/com~apple~CloudDocs/Course/*
DEST_ARCHIVE=/Volumes/Pleiades/CourseBackups/Test.7z  
echo "Backup up ${SOURCE_DIR} to ${DEST_ARCHIVE}./n"
/Applications/Keka.app/Contents/Resources/keka7z a ${DEST_ARCHIVE} -r "${SOURCE_DIR}"
The problem is that kaka7z is tripping over the source directory because of the space. It tries to back up "~/Library/Mobile" instead of the full path. I have no choice about that space because that is where the iCloud drive is located on macOS. I have tried quotation marks everywhere that I can think of and nothing works.

Using the command line directly works just fine:

Code: Select all

/Applications/Keka.app/Contents/Resources/keka7z a ${DEST_ARCHIVE} -r "~/Library/Mobile\ Documents/com~apple~CloudDocs//*"
Regarding the script, what does work is if I make a soft link then use that instead in the command:

Code: Select all

ln -s ~/Library/Mobile\ Documents/com~apple~CloudDocs/Course Course
The result is a link called "Course" and setting SOURCE_DIR=Course works swimmingly.

It's certainly workable but perhaps someone knows how to get this original path with the the space to work in the script. Any ideas?

Re: Spaces in filenames

Posted: Sun Sep 10, 2017 7:53 pm
by aone
Your code is working for me... I've tried with another path with spaces because "~/Library/Mobile\ Documents" does not exists in my environment.

Code: Select all

#! /bin/bash
SOURCE_DIR=~/VirtualBox\ VMs/Test/
DEST_ARCHIVE=~/Desktop/Test.7z  
echo "Backup up ${SOURCE_DIR} to ${DEST_ARCHIVE}./n"
/Applications/Keka.app/Contents/Resources/keka7z a ${DEST_ARCHIVE} "${SOURCE_DIR}"
Just curious, why the -r flag?

Re: Spaces in filenames

Posted: Sun Sep 10, 2017 7:56 pm
by aangel
Hmmm....not sure what to try next if it's working for you.

I'm unfamiliar with 7z and I added the -r switch thinking it was needed to recurse through the directories. Looking back, it might have been the space in the path that was causing 7z to fail and not the lack of the -r switch if the default behavior of 7z is to recurse.

Re: Spaces in filenames

Posted: Sun Sep 10, 2017 8:06 pm
by aone
If it's ok for you, try with full path and quotes, so no need to scape the folder space:

Code: Select all

#! /bin/bash
SOURCE_DIR="/Users/aone/VirtualBox VMs/Test/"
DEST_ARCHIVE="/Users/aone/Desktop/Test.7z"
echo "Backup up ${SOURCE_DIR} to ${DEST_ARCHIVE}.\n"
/Applications/Keka.app/Contents/Resources/keka7z a ${DEST_ARCHIVE} "${SOURCE_DIR}"
Maybe this other way works for you...

Re: Spaces in filenames

Posted: Sun Sep 10, 2017 9:03 pm
by aangel
This is now working for me, thank you! Changed a few other lines, too:

Code: Select all

printf "Source: ${SOURCE_DIR}\nDestination: ${DEST_ARCHIVE}.\n"
/Applications/Keka.app/Contents/Resources/keka7z a ${DEST_ARCHIVE} -x!.DS_Store "${SOURCE_DIR}"

Re: Spaces in filenames

Posted: Sun Sep 10, 2017 9:44 pm
by aone
Glad to help :)