Python clears the method for script in all files in the specified directory

Source: Internet
Author: User
Tags dot net
The example in this article describes how Python clears script in all files in a specified directory. Share to everyone for your reference. Specific as follows:

Save the script as stripscripts.py
Call syntax: Python stripscripts.py
Usage Example: Python stripscripts.py d:\myfiles

# Hello, this was a script written in Python. See Http://www.pyhon.orgimport Os,sys,string,remessage = "" "Stripscripts 1.1p-script stripper This Script would walk a D Irectory (and its subdirectories) and disable all scripts (JavaScript, VBScript ...) from. html and. htm files. (The scripts is not being deleted, but simply deactivated, so that's can review them if you like.) Can be usefull for sites you has downloaded with httrack or similar tools. No more nosey or buggy scripts in your local HTML files. Syntax:python%s
 
  Example:python%s D:\myfiles This script was public domain. You can freely reuse it. The author is Sebastien Sauvage
  
   
    Http://sebsauvage.net more Quick & dirty scripts is available at http://sebsauvage.net/python/"" "% ((sys.argv[0 ],) def stripscripts (Directorystart): Os.path.walk (Directorystart, Callback, ') def callback (args, directory,      files): print ' scanning ', directory for FileName in Files:if os.path.isfile (Os.path.join (directory,filename)): If String.Lower (Os.path.splitext (FileName) [1]) in ['. html ', '. htm ']: stripscriptfromhtml (Os.path.join (directo Ry,filename)) def stripscriptfromhtml (filepath): print ' processing ', Os.path.split (filepath) [1] File = open (filepath , ' RB ') HTML = File.read () file.close () RegExp = Re.compile (R ')
   
    
      ', Re. IGNORECASE) HTML = regexp.sub (' 
      
    
   
  
 
Related Article

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.