Python How to Batch extract Win10 lock screen Wallpaper

Source: Internet
Author: User
This article mainly introduces the use of Python batch extract Win10 lock screen Wallpaper Related Materials, the text through the sample code introduced in very detailed, hope to help everyone.

Objective

Believe that the use of WIN10 friends will find that every boot lock screen will have a different beautiful picture, these pictures are usually selected from the excellent photography, very beautiful.

But because the system will automatically replace these pictures, so even if the picture is good-looking, perhaps the next time after the boot is replaced.

With Python, we can extract these beautiful lock screen images in batches with a few simple lines of code. Set your favorite pictures to a desktop background without worrying about being replaced.

The following words do not say much, come together to see the detailed introduction.

Extraction principle

WIN10 system will automatically download the latest lock screen wallpaper and save them in a system folder, the path is c:\users\[user name]\appdata\local\packages\ Microsoft.windows.contentdeliverymanager_cw5n1h2txyewy\localstate\assets

Open this folder directly, there will be randomly named multiple files, each file is a picture. However, the file does not have a preview because it has no extension. In order not to spoil the system files and turn these files into a preview format, we use Python to copy these files, plus jpg as the extension.

Implementation code


Import OS, shutilfrom datetime import datetime# the directory Wallpapers folder where the file is stored as the directory where the picture is saved save_folder = Dir_path = Os.path.dirname ( Os.path.realpath (__file__)) + ' \wallpapers ' # Dynamic acquisition system holds the location of the lock screen picture Wallpaper_folder = os.getenv (' localappdata ') + (' \ Packages\microsoft.windows.contentdeliverymanager_cw5n1h2txyewy ' \localstate\assets ') # list all Files wallpapers = Os.listdir (Wallpaper_folder) for wallpaper in Wallpapers:wallpaper_path = Os.path.join (Wallpaper_folder, wallpaper) # Less than 150KB is not a lock screen picture if (Os.path.getsize (Wallpaper_path)/1024x768) < 150:continue wallpaper_name = wallpaper + '. jpg ' Save_pat h = Os.path.join (Save_folder, Wallpaper_name) shutil.copyfile (Wallpaper_path, Save_path) print (' Save wallpaper ' + save_ Path

First determine the system to hold the lock screen picture folder location, because the folder is located in the user's personal folder, each user's user name is not the same, so we need to pass the system localappdata variable dynamic access to the path. The code will save the extracted images in the wallpapers folder, so the directory where the code files are not wallpapers folder, you need to create a manual.

Execute the above Python code, and then open the Wallpapers folder, you can see the extracted lock screen picture.

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.