-3

I have problem about my code in below, help me please for correct my code

import glob 
import os 
import shutil from zipfile 
import ZipFile from os 
import path from shutil 
import make_archive

def main():
    list_of_files = glob.glob('C:\\Users\\RezaPal\\Desktop\\test compress\\.docx')
    latest_file = max(list_of_files, key=os.path.getctime)
    # Check if file exists
        if path.exists(latest_file):
    # get the path to the file in the current directory
        src = path.realpath(latest_file);
    # rename the original file
        #os.rename("backup_filetest.docx","filetest.docx")
    # now put things into a ZIP archive
        #root_dir,tail = path.split(src)
        #shutil.make_archive("guru99 archive", "zip", root_dir)
    # more fine-grained control over ZIP files
        with ZipFile("backup_filetest.zip","w") as newzip:
        newzip.write("filetest.docx")
            newzip.write("filetest.docx.bak")

if __name__== "__main__":
    main()
FBruzzesi
  • 6,385
  • 3
  • 15
  • 37
  • 1
    Indentation is extremely important in Python. Yours is incorrect. https://docs.python.org/2.0/ref/indentation.html – 001 Sep 04 '20 at 02:45
  • You need to format the code properly. Blocks should be indented with either 4 spaces, or tabs (don't use both) – flakes Sep 04 '20 at 02:46
  • Does this answer your question? [Why am I getting "IndentationError: expected an indented block"?](https://stackoverflow.com/questions/4446366/why-am-i-getting-indentationerror-expected-an-indented-block) – Carlo Zanocco Sep 04 '20 at 14:50

1 Answers1

-1

Correct code:

def main():
    list_of_files = glob.glob('C:\\Users\\RezaPal\\Desktop\\test compress\\.docx')
    latest_file = max(list_of_files, key=os.path.getctime)
    # Check if file exists
    if path.exists(latest_file):
    # get the path to the file in the current directory
        src = path.realpath(latest_file);
    # rename the original file
        #os.rename("backup_filetest.docx","filetest.docx")
    # now put things into a ZIP archive
        #root_dir,tail = path.split(src)
        #shutil.make_archive("guru99 archive", "zip", root_dir)
    # more fine-grained control over ZIP files
    with ZipFile("backup_filetest.zip","w") as newzip:
        newzip.write("filetest.docx")
        newzip.write("filetest.docx.bak")


if __name__== "__main__":
      main()

I don't know how the "whith"-block should be executed: with a condition or not. Consider this point.

cauf
  • 103
  • 7