cat40 cat40 - 1 year ago 71
Bash Question from external drive

I'm trying to run a Python script off of an external drive. The script runs fine, but when it reaches the line, shell=True)
, I get the error (from command prompt)
the filename, directory name, or volume label syntax is incorrect
. When I run the same script off of the C drive, it works fine and copies the files. Python is installed on the C drive, and the external drive is a microSD card if it matters. Python version is 3.4, but it needs to work on Python 2.7 as well.

Relevent code:

paths = [os.path.join(dirpath, fname) for dirpath, __, fnames in os.walk('.\\MUSIC') for fname in fnames]
for path in paths:
pathcomp = path.replace('.\\MUSIC', 'C:\\redacted\\Music\\MUSIC')
if not os.path.isfile(pathcomp):
abspath = os.path.abspath(path)
callThis = 'copy "'+abspath+'" "'+os.path.dirname(pathcomp)+'"'
print(callThis)[callThis], shell=True)

outputs something similar to

copy "G:\MUSIC\dir1\dir2\fname.mp3" "C:\redacted\Music\MUSIC\dir1\dir2\fname.mp3"

Typing that exact line into command prompt works fine and copies the file.

I think the problem has something to do with the command prompt running out of the C drive instead of the external drive. How can I make it run out of the external drive (show
instead of
in the python script? I tried `'G:', shell=True) but have the same problem.

Answer Source

Passing a list to overrides the shell tokenization rules. You should pass a string to the call function instead.,shell=True)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download