【发布时间】:2011-02-14 22:19:35
【问题描述】:
我是 VBS 的新手。我需要帮助来执行以下步骤;
1) 在某个位置找到最新修改的文件夹(日期时间最近的文件夹),比如说 C:\temp。
2)然后在(上述文件夹的)子文件夹中找到特定文件(扩展名为.txt)
3) 将该文件复制到另一个位置,假设 C:\temp1
4) 将文件名重命名为当前日期,例如 2011-02-14
谢谢
【问题讨论】:
标签: vbscript
我是 VBS 的新手。我需要帮助来执行以下步骤;
1) 在某个位置找到最新修改的文件夹(日期时间最近的文件夹),比如说 C:\temp。
2)然后在(上述文件夹的)子文件夹中找到特定文件(扩展名为.txt)
3) 将该文件复制到另一个位置,假设 C:\temp1
4) 将文件名重命名为当前日期,例如 2011-02-14
谢谢
【问题讨论】:
标签: vbscript
VBScript:
BaseDir = "C:\Temp"
FileToFind = "test.txt"
Set fs = CreateObject("Scripting.FileSystemObject")
Set fl = fs.GetFolder(BaseDir)
For Each sfl In fl.SubFolders
If IsNull(fd) Or sfl.DateCreated > fd Then
fd = sfl.DateCreated
Found = sfl.Path & "\"
End If
Next
Set f = fs.GetFile(Found & FileToFind)
f.Copy "C:\Temp1\" & Year(Date) & Month(Date) & Day(Date), True
文件名中包含“-”可能有问题,所以我省略了。
【讨论】:
这是一些伪代码,您将如何在 Windows 上的 bash 中执行此操作(使用 cygwin)
# change to the directory so we can avoid path issues
cd /path/to/temp
# get the most recently modified directory
myDirectory = "`ls -drt */ | tail -n1`"
# change to that directory
cd "$myDirectory"
# Here you can use cp or mv depending if you want to remove the file from orig
directory
cp "specificFile.txt" "/path/to/temp1/`date command with flags`.txt"
【讨论】: