20231111

编程入门 行业动态 更新时间:2024-10-08 20:40:11

20231111

20231111

使用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 = NothingMsgBox "Successful!"

使用VBScript修改注册表,从而修改Windows 10 记事本默认文本编码(有问题 注册表可以修改 但是好像没什么效果)

Const HKEY_CURRENT_USER = &H80000001Dim objRegistry, strKeyPath, strValueNameDim 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 = FalseFor i = 0 To UBound(valueNames)If valueNames(i) = strValueName ThenvalueExists = TrueExit ForEnd If
Next' 显示结果
If valueExists Then' 注册表键已存在,直接修改值objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, targetValueMsgBox "Value exists! Value = " & targetValue
Else' 注册表键不存在,创建键并设置值objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPathobjRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, targetValueMsgBox "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(隐藏命令提示符窗口)

更多推荐

20231111

本文发布于:2023-11-15 09:28:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1597424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!