python--file Delete, determine directory presence, string substitution

Source: Internet
Author: User

Last night written a test development volume of Jinshan WPS, make a note (but not the answer, just my idea), about the file and string processing is writing and perfect the first blog, now the title is as follows:

1. Delete all files in the E:\ABC directory using the scripting language:

Use Os.path.exists () to determine if the E:\ABC directory exists, and if there are any files (including subfolders) that use the Shutil.rmtree cascade Delete directory, the error is not present. Note that the Os.remove function cannot delete a folder that has child files.

2. Write a script replacement folder where all the suffixes named. txt are replaced with "= 0" (including the. txt file in the subfolder) in the row containing "= 1":

Use Os.path.exists () to determine if a folder directory exists, and if so, use the stack to traverse the file tree, read the. txt file, and replace the string with the String.Replace () method to re-write to the. txt file.

3. Write a script that batches 100 txt files placed in the D:\temp directory:

To determine whether a directory exists, open the file using the opening method, write the file using the Write method, before you need to determine whether the file name is duplicated.

4. Please design 1 methods to test the WINAPI interface: FindWindow or SetWindowText,

SendMessage Interface Definition: HWND WINAPI FindWindow (lpctstr lpclassname, LPCTSTR lpwindowname);

SetWindowText Interface Definition: BOOL SetWindowText (HWND hwnd, LPCTSTR lpstring)

Algorithms and data Structures:

1. Write down all primes within 1000;

2. Write a sorting algorithm or a de-weight algorithm.

python--file Delete, determine directory presence, string substitution

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.