使用VBScript,存在问题(当图片名称中有中文时,保存的TXT文本为ANSI编码)
Dim FileSystem, Folder, File, TextFile
' 创建文件系统对象
Set FileSystem = CreateObject("Scripting.FileSystemObject")
' 获取当前目录路径
Set Folder = FileSystem.GetFolder(".")
' 创建 TXT 文件
Set TextFile = FileSystem.CreateTextFile("Data.txt", True)
' 遍历当前目录中的文件
For Each File In Folder.Files
' 检查文件扩展名是否为图片格式
If LCase(Right(File.Name, 4)) = ".jpg" Or _
LCase(Right(File.Name, 5)) = ".jpeg" Or _
LCase(Right(File.Name, 4)) = ".png" Or _
LCase(Right(File.Name, 4)) = ".gif" Then
' 将文件名写入 TXT 文件
TextFile.WriteLine(File.Name)
End If
Next
' 关闭 TXT 文件
TextFile.Close
' 释放对象
Set TextFile = Nothing
Set Folder = Nothing
Set FileSystem = Nothing
MsgBox "Successful!"
使用VBScript修改注册表,从而修改Windows 10 记事本默认文本编码(有问题 注册表可以修改 但是好像没什么效果)
Const HKEY_CURRENT_USER = &H80000001
Dim objRegistry, strKeyPath, strValueName
Dim targetValue
' 注册表键路径
strKeyPath = "Software\Microsoft\Notepad"
' 注册表值名称
strValueName = "iDefaultEncoding"
' 注册表值数据(DWORD 值)
targetValue = 0 ' 这里使用 5 作为示例数值
' 创建注册表对象
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
' 检查注册表键值是否存在
Dim valueNames, valueTypes
objRegistry.EnumValues HKEY_CURRENT_USER, strKeyPath, valueNames, valueTypes
' 判断指定值是否存在
Dim valueExists
valueExists = False
For i = 0 To UBound(valueNames)
If valueNames(i) = strValueName Then
valueExists = True
Exit For
End If
Next
' 显示结果
If valueExists Then
' 注册表键已存在,直接修改值
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, targetValue
MsgBox "Value exists! Value = " & targetValue
Else
' 注册表键不存在,创建键并设置值
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, targetValue
MsgBox "Value does not exist."
End If
' 释放对象
Set objRegistry = Nothing
通过Python实现
import os
import codecs
# 获取当前文件夹路径
folder_path = os.getcwd()
# 获取当前文件夹下的所有文件
file_names = os.listdir(folder_path)
# 过滤出图片文件(假设只包含常见的图片文件格式)
image_extensions = ['.jpg', '.jpeg', '.png', '.gif']
image_files = [file for file in file_names if os.path.isfile(os.path.join(folder_path, file)) and os.path.splitext(file)[1].lower() in image_extensions]
# 将图片文件名保存到文本文件
output_file = "Data.txt"
with codecs.open(output_file, "w", encoding="utf-8") as file:
file.write('\n'.join(image_files))
print("图片文件名已保存到", output_file)
将Python文件打包成exe方法(使用PyInstaller):
① 安装:pip install pyinstaller
② 打包:pyinstaller --onefile your_script.py(执行时会弹出cmd)
pyinstaller --onefile --noconsole your_script.py(隐藏命令提示符窗口)