使用 VBScript 移动和重命名文件 [英] Moving and Renaming Files Using VBScript

查看:41
本文介绍了使用 VBScript 移动和重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事实证明,我现在被要求修改脚本,以便将每个相应的文件传送到自己的文件夹中.所有文件都将驻留在 AS400 上的一个文件夹中,并将移动到另一台计算机上的不同文件夹中.我的问题是我可以摆脱这样的事情:

As it turns out I am now being asked to modify the script so it delivers each respective file into its own folder. All files will reside in one folder on a AS400 and will move to different folders on a separate computer. My question is can I get away with something like:

Dim fso,f,strPathBuild

Set fso=CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("Z:\SOURCE")

For Each file In f.Files

if left(UCase(file.Name),1) = "A" then strPathBuild = Replace(file, "Z:\SOURCE", "Y:\DESTINATION1")

if left(UCase(file.Name),1) = "A" then strPathBuild = Replace(strPathBuild,"A","ACKNOWLEDGE")

if left(UCase(file.Name),1) = "S" then strPathBuild = Replace(file, "Z:\SOURCE", "Y:\DESTINATION2")

if left(UCase(file.Name),1) = "S" then strPathBuild = Replace(strPathBuild,"S","SHIPMENT")

fso.MoveFile file, strPathBuild

Next

Set f = Nothing
Set fso = Nothing

我很抱歉,但似乎 PM 不喜欢一次性给我所有要求.

I apologize but it seems the PM likes to refrain from giving me all the requirements at once.

推荐答案

回答您评论的问题:

Dim fso,f,strPathBuild

Set fso=CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("Z:\SOURCE")

For Each file In f.Files

strPathBuild = Replace(file, "Z:\SOURCE", "Y:\DESTINATION")

if left(UCase(file.Name),1) = "A" then strPathBuild = Replace(strPathBuild,"ACK","ACKNOWLEDGE")

fso.MoveFile file, strPathBuild

Next

Set f = Nothing
Set fso = Nothing

此外,正如 Alex K 所说,您要开始注意文件名是否区分大小写.(这就是我包含 UCase 函数的原因)

Also, as Alex K says, you want to start watching out for case sensitivity on your file names. (That's why I included the UCase function)

这篇关于使用 VBScript 移动和重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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