1

I would like to use a loop for uploading some files to a blob container. i.e.files xaa,xab,xac

I have tried the following loop but no success

import string    
for i in string.lowercase[0:2]:
        block_blob_service.create_blob_from_path(
            'my_container',
            'xa%s' % i,
            '/pathtomylocalfile/xa%s' % i)

while this works

block_blob_service.create_blob_from_path(
            'my_container',
            'xaa',
            '/pathtomylocalfile/xaa')
2
  • You have any errors with the first approach? Commented Apr 29, 2016 at 10:03
  • no just standing by with no network trafic Commented Apr 29, 2016 at 10:03

3 Answers 3

1

Otherwise, you can try to use format function to format your string:

...
    block_blob_service.create_blob_from_path(
            'my_container',
            'xa{}'.format(i),
            '/pathtomylocalfile/xa{}'.format(i))
Sign up to request clarification or add additional context in comments.

Comments

0

Strange that seems to work as an alternative

from os import listdir
from os.path import isfile, join
onlyfiles = [f for f in listdir('/mylocaldirectory/') if isfile(join('/mylocaldirectory/', f))]

for i in onlyfiles:
    block_blob_service.create_blob_from_path(
        'mycontainer',
        '%s' % i,
        '/mylocaldirectory/%s' % i)

Comments

0
    import os

    FILE_PATH1="/pathtomylocalfile"
    container_name ='my_container'

    local_path=os.path.expanduser(FILE_PATH1)

    for root, dirs, allfiles in os.walk(FILE_PATH1):
        print(root)

        for f in allfiles:
            print(os.path.join(root, f))

            local_file_name = f

            full_path_to_file =os.path.join(root, local_file_name)


            if full_path_to_file.find(".") != False:
                print("Temp file = " + full_path_to_file)
                print("\nUploading to Blob storage as blob " + local_file_name)


                block_blob_service.create_blob_from_path(container_name, full_path_to_file[1:], full_path_to_file)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.