复制和重命名文件 VBScript [英] Copy and Rename File VBScript

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

问题描述

我需要将名称基于日期的文件移动到另一个文件夹.

I need to move a file with a name based off of a date to another folder.

文件结构为:
来源: \\network_location\folder\Filename_09-11-2012.txt

目的地: C:\Dump\Filename.txt

源文件总是滞后 1 天.我希望在复制文件时重命名该文件.
我尝试使用的代码是:

The source file is always 1 day behind. I am looking to rename the file while copying it.
The code I am trying to use is:

Sub Copy_And_Rename()
    Name "\\network_location\folder\Filename_"+Month(Now())+"-"+Day(Now()-1)+"-"+Year(Now())+".txt" As "C:\Dump\Filename.txt"
End Sub

推荐答案

您可以像这样使用 FileSystemObject 复制和重命名文件:

You can copy and rename a file with the FileSystemObject like this:

Set objFSO = CreateObject("Scripting.FileSystemObject")
' First parameter: original location\file
' Second parameter: new location\file
objFSO.CopyFile "C:\Test\folder1\name1.txt", "C:\Test\folder2\name2.txt"

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

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