Get path from file name

Below is the code, but I would like to leave a comment filename = os.path.basename (filename) , when I do this, I can not specify the absolute path for filename , because k.set_contents_from_filename no longer refers to the actual file location, only the file in the current working directory will work if not to comment. If I do not use file_name = os.path.basename (file name) , the file will be downloaded with a predefined path. Any ideas?

# List files in directory and upload them to bucket
    for filename in all_files:
        #skip all directory entries which are not a file
        if not os.path.isfile(filename):
              continue
        #filename = os.path.basename(filename)           
        k = Key(bucket)
        k.key = filename
        k.set_contents_from_filename(filename, cb=percent_cb, num_cb=10)
+3
source share
1 answer

If I am missing something completely, why can't you do something like that?

# List files in directory and upload them to bucket
for filename in all_files:
    #skip all directory entries which are not a file
    if not os.path.isfile(filename):
          continue    
    k = Key(bucket)
    k.key = os.path.basename(filename)
    k.set_contents_from_filename(filename, cb=percent_cb, num_cb=10)
+6
source

All Articles