Example of using python to delete nginx cached files (python file operation)

Source: Internet
Author: User
This article describes how to use python to delete nginx cache files (python file operations). For more information, see enter parameters for the next call, such as: www.bitscn.com/#delete the cache on the first page of www.bitscn.com.

The code is as follows:


# Coding = utf8
Import sys, OS
Import hashlib
If len (sys. argv) <2:
Print ("You did not enter the address. ")
Sys. exit ()
Path = "/home/cache" # cache Directory
Md5v = hashlib. md5 (sys. argv [1]. encode (encoding = 'gb2312 '). hexdigest () # obtain the file hash value
Onep = md5v [31: 32]
Twop = md5v [29:31]
Filename = path + "/" + onep + "/" + twop + "/" + md5v
If OS. path. isfile (filename ):
If OS. remove (filename) = None:
Print (filename + "=> cleared successfully ")
Else:
Print ("failed to clear ")
Else:
Print ("this cached file is not available ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.