Vbscript删除名称中带有特殊字符的文件 [英] Vbscript to delete files with special characters in their name

查看:124
本文介绍了Vbscript删除名称中带有特殊字符的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了如何使用VBScript删除文件,但是对于某些包含特殊字符的文件名.

I have found how to delete files using VBScript, but for certain filenames that include special characters.

例如:我有一个要安装的游戏(《模拟人生3》),然后进行自我更新.我想使用更新随附的更新的快捷方式,称为"TS3W",因为它会自动加载您的最新扩展,从而使我免于使用多个快捷方式.我已经创建了一个脚本来创建该快捷方式,但是我无法删除旧的快捷方式,因为它名为"The Sims 3™".

For example: I have a Game (The Sims 3) i have set up to install, then update itself. I want to use a newer shortcut that comes with the update called "TS3W" as it automatically loads your latest expansions, which saves me from using multiple shortcuts. I have already made a script to create that shortcut, but I cannot delete the old shortcut as it is called 'The Sims 3™'.

Vbscript无法识别'™'符号,因此找不到要删除的文件.

The '™' Symbol is not recognized by Vbscript and therefore cannot find the file to delete.

我可以使用某种脚本删除此类文件吗?

Is there any way I can delete such files using a script of some kind?

推荐答案

在VBScript中,您将执行以下操作:

In VBScript you'd do something like this:

Set fso = CreateObject("Scripting.FileSystemObject")
filename = "C:\path\to\The Sims 3™.lnk"
If fso.FileExists(filename) Then fso.DeleteFile filename, True

尽管如此,您也应该可以批量进行这项工作.尝试在脚本中将代码页设置为1251:

You should be able to make this work in batch as well, though. Try setting the codepage to 1251 in your script:

@echo off
chcp 1251 >nul
del /q "C:\path\to\The Sims 3™.lnk"

这篇关于Vbscript删除名称中带有特殊字符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆