本文介绍了将文件从不同的目的地复制到1个文件夹&用日期重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家下午好。 要说我是绿色的V / VBS是轻描淡写的,但是在这个网站上有很多例子,我能够把一起使用的基本脚本: 转到服务器A /目录/文件夹 将文件X复制到服务器B /目录/文件夹 和用原始名称重命名,但是将当前日期添加到它。 我想知道是否可以: 修改脚本转到服务器/文件夹 检索文件(不同名称) 将它们复制到特定的服务器/目录/文件夹 将它们重命名为它们的原始名称,但是将当前日期添加到它。 或者为每个源/文件创建一个单独的脚本会不那么令人头疼? 以下是我的非常基本的复制/重命名脚本示例(F:\ =当前用于测试的本地驱动器) 我尝试了什么: Dim file1,file2 file1 =\\\\\\\\\\ \\ FOLDER \ .FILE.BAK file2 =F:\ Test \ .FILE&年(日期)&对(0和月(日期),2)&正确(0和日(日期),2)& .BAK 设置fso = CreateObject(Scripting.FileSystemObject) 如果是fso。 FileExists(file1)= true然后 如果fso.FileExists(file2)= true那么 fso.DeleteFile(file2) 如果 fso.CopyFile file1,file2 'else 'msgbox文件不存在 结束如果 设置FSO = Nothing 解决方案 \ FOLDER \ .FILE.BAK file2 =F:\Test \ FILE& year(date)& Right(0& month(date),2)& Right(0& Day(Date) ,2)&。BAK 设置fso = CreateObject(Scripting.FileSystemObject) 如果fso.FileExists(file1)= true那么 如果fso.FileExists(file2)= true那么 fso.DeleteFile(file2) 结束如果 fso.CopyFile file1,file2 'else 'msgbox文件没有存在 结束如果 设置FSO = Nothing 我认为你需要 DirectoryInfo.GetFiles(),请参见此处的示例: DirectoryInfo.GetFiles方法(System.IO) [ ^ ] 如果要将此作为没有Visual Studio的脚本运行,可以使用 Powershell ,请参阅此处的示例: .net - Powershell - IO.Directory - 查找所有子目录中的文件类型 - Stack溢出 [ ^ ] Good afternoon all.To say that I'm green w/ VBS is an understatement, but following many examples on this site, I was able to put together a basic script that will: go to server A / directory / folder copy file X to server B / directory / folder and rename it with the original name but add the current date to it.I was wondering if it is possible to: modify the script to go to servers / folders retrieve files (of different names) copy them to a specific server / directory / folder rename them with their original name but add the current date to it.Or would it be less headaches to just create a separate script for each source / file ?Below is an example of my, VERY BASIC, copy / rename script (F:\ = current local drive for testing)What I have tried:Dim file1, file2file1 = "\\server A\d$\FOLDER\FILE.BAK"file2 = "F:\Test\FILE" & year(date) & Right("0" & month(date),2) & Right("0" & Day(Date),2) & ".BAK"Set fso = CreateObject("Scripting.FileSystemObject")If fso.FileExists(file1) = true then If fso.FileExists(file2) = true then fso.DeleteFile(file2) End if fso.CopyFile file1, file2'else' msgbox "File does not exist"End If Set FSO = Nothing 解决方案 \FOLDER\FILE.BAK"file2 = "F:\Test\FILE" & year(date) & Right("0" & month(date),2) & Right("0" & Day(Date),2) & ".BAK"Set fso = CreateObject("Scripting.FileSystemObject")If fso.FileExists(file1) = true then If fso.FileExists(file2) = true then fso.DeleteFile(file2) End if fso.CopyFile file1, file2'else' msgbox "File does not exist"End If Set FSO = NothingI think you need DirectoryInfo.GetFiles(), see example here: DirectoryInfo.GetFiles Method (System.IO)[^]If you want to run this as a script without Visual Studio you can use Powershell, see example here: .net - Powershell - IO.Directory - Find file types in all subdirectories - Stack Overflow[^] 这篇关于将文件从不同的目的地复制到1个文件夹&用日期重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-26 05:12