To delete a file package function

First, we we need to create a 11.txt file as shown:

import os

def delFile(fileNname):
    if isFile:
        os.remove(fileNname)
        return
    else:
        return False
def isFile(fileName):
    if os.path.isfile(fileName):
        return True
    else:
        return False

if __name__ == '__main__':


    a = input('请输入文件路径:\n')
    delFile('{}'.format(a))

Run the program:

Please enter a file path: 
F: \ QQ file \ python learning \ Practice Code \ 11.txt

We need to remove the path and file name of the file in the program run panel input (each layer folders and files civil \ separated)

Finally, we can see the following figure, 11.txt file has been deleted

 

Guess you like

Origin www.cnblogs.com/ldmb/p/12008042.html
Recommended