[Script Tool] QQ Personal Data Management Methods and Scripts

Penguin User Data Cleanup Pain Points

Computer QQ users have a long-term pain point, that is, QQ often downloads useless advertisements, chat pictures, file caches, occupies a large amount of disk space, causing the C disk to burst.

There are many ways to clean up the web, but they are all messy. There are probably several ways I can clean up data as I search for it:

(1) Delete the chat record of a specific group/private chat: directly in the Message Manager

(2) The "File Management - Personal Folder Cleanup" that comes with QQ

By default, it is placed under a folder called Tencent Files\QQ, which can be customized.

(3) XX computer stewardship and other third-party detection and cleaning software

Not used. I don't want to install the whole software for a small need.

(4) Manually find the data storage directory for cleaning up

It's often difficult to know exactly what path you can clean, and manual cleaning is too tiring.

There are many problems left over from the above approaches. For example, it feels like the cleaning is not complete or the scanning process is too slow. If it's an old computer, it can crash.

The basic reason for this is that the penguin's file construction method is so sb that some folders are hard to detect (such as the group2 folder) and makes the iteration process cumbersome.

Discussions on related issues can refer to Knowing Questions: How can there be one more Group2 for group picture storage under QQ folder? - Know

In addition, we also have some more personalized needs of our own, which can't be taken care of by common methods and are too tired to finish manually.

So I decided to start with the QQ local folder and solve this problem once and for all by using a fine catalog disassembly method and scripting to delete those files that do not need to be preserved for''me''.

It's important to note that the purpose of sharing the tutorial is not to let the copy code finish, but to understand the core approach to building this script.

Understanding the structure of QQ folders

For ease of management, I draw a separate partition from the disk (i.e. the F disk) to store QQ, WeChat's normal and clear data to avoid harming the C disk. (And because I underestimated the space, it exploded in less than a few days, so I'm writing this script...)

Taking the default directory Tencent Files as an example, generally there are subdirectories with QQ numbers and All Users subdirectories below.

First clean up the QQ directory. This directory represents the data for this account.

With regard to the lower folders, I have listed a table summarizing what they are responsible for (referencing online materials and hands-on testing) and the processing strategies they take:

This table is just a list. Many of the unknown uses (especially encrypted databases such as.db) will be left untouched. I will gradually complete this table in the future.

Overall, there are approximately three processing strategies:

(1) deleted immediately

Deleting advertisements, group chat pictures, and various renewable caches will have no effect.

(2) Regular cleaning up

For example, working files, voice, etc. n months ago, this is very understandable.

(3) Long-term reserved

Delete files at greater risk unless you need to migrate data in bulk, such as changing computers. For example, msg3.0index.db, Msg3. These two large files, 0.db, collect all the QQ chat records. There is a high risk of deleting them directly, but the file size is growing every day without deleting them, taking up a lot of space.

Related discussions can be referred to in this article win10 PC C Disk Memory Reduction Solution (C Disk Full, Msg3.0index.db)_ Clean and innocent blog-CSDN blog_ Msg3. 0index

Once you have defined which files you want to clean up, you can start writing scripts.

Write a simple powershell script

Because I'm using windows, I wrote a QQcleaner with powershell. PS1 script. (If it's a linux system, the same should be true)

Today's rough version implements that specific folders can be cleaned up, files can be cleaned up before customized days of "regular cleanup class" data, and multiple QQ accounts can be processed.

To illustrate, there are many bugs in the script, and each person's folder situation may be different and needs to be adjusted.

There are several main powershell commands involved in the script:

#0.Mute variable declaration
$myQQfiledir=<Path to default directory> #Such as Tencent Files
$id=<QQ Number>
$TimeOutDays=14 #Assume cleaning up files half a month ago

#1. Commands to delete files and folders (for example, \Ads)
Remove-Item $myQQfiledir$id\Ads -Recurse 
# The -Recurse parameter is designed to recursively delete all the subitems below, in addition to -force, -confirm, and so on.
# This can actually be changed to not delete the Ads folder, just delete the subitems below. But even if QQ is deleted, it will be built back by itself, so deleting does not matter.

#2. foreach function for traversal
foreach(<variable> in <List of variables>)
{
    #Statements processed
}

#3. Print process statement to screen
Write-Host ('Now cleaning:'+$filePath) #This may indicate which directory is currently being cleaned up

#4. Definition and invocation of functions
Function cleanlog ($id,$TimeOutDays) #Two parameters passed in
{
    #Contents of functions
}
cleanlog $id $TimeOutDays

#5. Extraction of time and date
get-date #System current date and time
$files.lastwritetime #$files Last modified time for this file
# Of course, you can also use $files. Calculate the last creation time of creationtime
((get-date)-$files.lastwritetime).days #Subtracts two times and represents the result in days

Full code:

#QQ File Cleanup Tool
#Command invoked in powershell: QQcleaner.ps1
#Enter set-ExecutionPolicy RemoteSigned if you encounter a prohibition

#default setting#
$myQQfiledir='C:\' #Set Default File Storage Directory in Tencent QQ
$QQnumbers='888888888','888888888' #My two QQ accounts
$TimeOutDays=14 #How many days ago

#Define Spam File Functions
Function cleanrubbish ($id)
{
    #Cleanable garbage
    Remove-Item $myQQfiledir$id\Ads -Recurse
    Remove-Item $myQQfiledir$id\QZoneLover -Recurse
    Remove-Item $myQQfiledir$id\CloudRes -Recurse
    Remove-Item $myQQfiledir$id\SelCreateGroupHead -Recurse
    Remove-Item $myQQfiledir$id\Audio -Recurse
    Remove-Item $myQQfiledir$id\VasscUpdate -Recurse
    Remove-Item $myQQfiledir$id\Image\HistroyHead -Recurse
    Remove-Item $myQQfiledir$id\Image\MarktingMsgCachePic -Recurse
    Remove-Item $myQQfiledir$id\Image\Thumbnails -Recurse
    Remove-Item $myQQfiledir$id\Image\PhotoWall -Recurse
    Remove-Item $myQQfiledir$id\Image\Group2\ -Recurse
    Remove-Item $myQQfiledir$id\Image\Group\ -Recurse
    Remove-Item $myQQfiledir$id\Image\PicFileThumbnails -Recurse

    Write-Host "finish!" 
}

#Define periodic file cleanup function
Function cleanlog ($id,$TimeOutDays)
{   #Define list of log directories to clean up
    $mylogdir=($myQQfiledir+$id+'\Image\C2C'),($myQQfiledir+$id+'\FileRecv\MobileFile'),($myQQfiledir+$id+'\Video' )
    foreach($filePath in $mylogdir)
    {   
        Write-Host ('Now cleaning:'+$filePath)
        $files=get-childitem -path $filePath  #Get all the files in the directory
        foreach($file in $files)
        {   #Calculate time from today (by last modified date or creation date)
            $daypan=((get-date)-$files.lastwritetime).days  #$daypan=((get-date)-$files.creationtime).days
            if ($daypan -gt $TimeOutDays)       
            {   #Determine whether a file has been cleaned up for more than a certain amount of time
                remove-item $files.fullname -Recurse -force
            }        
        }   
    }
}
    
#Batch execution
foreach($id in $QQnumbers)
{   
    Write-Host ">>>Now cleaning account:"$id
    #Call method: function name + QQ number
    cleanrubbish $id 
    cleanlog $id $TimeOutDays
    Remove-Item $myQQfiledir\files -Recurse #Delete generic files directory
}

Use of scripts

Call the ps1 script by entering <script name> in the script directory. ps1

The first time you run a powershell script, you will encounter a problem where windows does not have permission to execute the script. This is because the system defaults to Restricted execution policy and no scripts are allowed to run.

Solution: Run the powershell as an administrator, enter the set-ExecutionPolicy RemoteSigned command, and restart. Then you can use it directly.

That's what we're sharing today.

Next time we'll come up with a cleanup tutorial for Android QQ.

Keywords: Windows PowerShell

Added by MrJW on Fri, 25 Feb 2022 19:45:51 +0200