diff --git a/picard/file.py b/picard/file.py index 410c630d3..53a1e1ec5 100644 --- a/picard/file.py +++ b/picard/file.py @@ -369,7 +369,13 @@ class File(QtCore.QObject, Item): if sys.platform == "darwin": new_filename = unicodedata.normalize("NFD", new_filename) - return os.path.realpath(os.path.join(new_dirname, new_filename)) + new_path = os.path.join(new_dirname, new_filename) + try: + return os.path.realpath(new_path) + except FileNotFoundError: + # os.path.realpath can fail if cwd doesn't exist + return new_path + def _rename(self, old_filename, metadata): new_filename, ext = os.path.splitext( diff --git a/picard/util/filenaming.py b/picard/util/filenaming.py index 187bcfac8..6ae23affc 100644 --- a/picard/util/filenaming.py +++ b/picard/util/filenaming.py @@ -23,6 +23,7 @@ import struct import sys import unicodedata from picard.util import _io_encoding, decode_filename, encode_filename +from PyQt5.QtCore import QStandardPaths def _get_utf16_length(text): @@ -301,7 +302,12 @@ def make_short_filename(basedir, relpath, win_compat=False, relative_to=""): """ # only deal with absolute paths. it saves a lot of grief, # and is the right thing to do, even for renames. - basedir = os.path.abspath(basedir) + try: + basedir = os.path.abspath(basedir) + except FileNotFoundError: + # os.path.abspath raises an exception if basedir is a relative path and + # cwd doesn't exist anymore + basedir = QStandardPaths.writableLocation(QStandardPaths.MusicLocation) # also, make sure the relative path is clean relpath = os.path.normpath(relpath) if win_compat and relative_to: