相信大家都体验过以”小而美”著称的微信,这款神奇而伟大的软件无情的占据了每一个电脑的15g空间以上,而鄙人的电脑总空间…只有256…

微信的接受文件夹

于是,本人注定和微信有一场旷日持久的战斗。

微信与我而言最主要的问题有以下几点:

  1. 在微信中下载的文件如果在微信中直接打开会变成只读无法直接编辑
  2. 微信下载文件分散在各个文件夹内,甚至不同人发送的不同文件都会占用同一份内存
  3. 当同名文件发送,微信会默默的在文件名后面加上一个”(1)”

综上所述,写一个自动化脚本将各个文件夹内的接受文件转移到单独文件夹内是非常合理的。

代码如下 (macOS):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!~/opt/anaconda3/bin/python
# -\*- coding: utf-8 -\*-

# Import the necessary modules
import os
import shutil


# Define the file path to the source directory
filePath="/Users/sandy/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/e5935df9a7a640bff14105be4661fcb4/Message/MessageTemp"

dst_dir = "/Users/sandy/Library/Mobile Documents/com~apple~CloudDocs/Downloads/wechatDownloadFiles"

# Get a list of files in the source directory
get_files_sourceDir = os.listdir(filePath)

# Iterate over each file in the source directory

for file_sourceDir in get_files_sourceDir:
# Define the path to the file within the source directory
file_source = filePath+"/"+file_sourceDir+"/File"

# Check if the file exists
if os.path.exists(file_source):
# Get a list of files in the file_source directory
get_files = os.listdir(file_source)

# Iterate over each file in the file_source directory
for file_ in get_files:
# Define the source and destination file paths
src_file = os.path.join(file_source, file_)
dst_file = os.path.join(dst_dir, file_)
# Check if the destination file exists
if os.path.exists(dst_file):
# Check if the source and destination files are the same
if os.path.samefile(src_file, dst_file):
# If they are the same, skip this iteration of the loop
continue
# If they are not the same, remove the destination file
os.remove(dst_file)
# Move the file from the source directory to the destination directory
shutil.move(file_source + "/" + file_, dst_dir)
# Print the name of the file that was moved
print(file_)
else:
# If the file does not exist, print an error message
print("The file does not exist")

微信的默认接受文件夹可以在微信中接受文件后右键获取。

如果是macOS可以使用自带的crontab进行自动化运行,使用方法是在terminal中输入crontab -e, 而后使用cron表达式 + 命令进行自动化部署。

1
0 23 \* \* \* /Users/sandy/opt/anaconda3/bin/python "/Users/sandy/Nutstore Files/Nutstore/shell/moveWechatFiles.py"

0 23 \* \* \*是cron表达式,代表每天23点。

python "moveWechatFiles.py"代表运行命令,注意可以使用绝对路径来避免运行失败。

另外,可以在之后加上>/dev/null 2>&1以去除运行日志减少空间利用。