TAGS :Viewed: 4 - Published at: a few seconds ago

[ Why am i getting an error: "buffsize musth be an integer" for mv shell command ]

Why am i getting an error: "buffsize musth be an integer"

afer this line:

pid2 = subprocess.Popen(["mv"],glob.glob(os.path.basename(filename)+'[0-9]*'),folder);

It is a simply mv command with a blog shell expansion .

I want sth like mv filename[0-9]* folder

Answer 1


First of all, it's Python, so you don't need a semi-colon at the end of a line. Then, what you want is to supply one argument, i.e.

pid2 = subprocess.Popen(["mv"] +
                        glob.glob(os.path.basename(filename)+'[0-9]*') +
                        [folder])

Otherwise, you're specifying the result of glob.glob as the second argument (bufsize) of subprocess.Popen.

Also note that calling mv is unnecessary, Python already has the functionality to move files implemented in shutil.move:

for f in glob.glob(os.path.basename(filename)+'[0-9]*'):
    shutil.move(f, folder)

Answer 2


As its first argument, Popen() takes either a string, or a list of arguments. You are just passing ["mv"]; the glob.glob(...) and folder get interpreted as the second and the third arguments to subprocess.Popen(), which are bufsize and executable.

Try:

args = ["mv"] + [glob.glob(os.path.basename(filename)+'[0-9]*')] + [folder]
pid2 = subprocess.Popen(args)