【问题标题】:Need to move file from one folder to another需要将文件从一个文件夹移动到另一个文件夹
【发布时间】:2011-02-14 22:19:35
【问题描述】:

我是 VBS 的新手。我需要帮助来执行以下步骤;

1) 在某个位置找到最新修改的文​​件夹(日期时间最近的文件夹),比如说 C:\temp。

2)然后在(上述文件夹的)子文件夹中找到特定文件(扩展名为.txt)

3) 将该文件复制到另一个位置,假设 C:\temp1

4) 将文件名重命名为当前日期,例如 2011-02-14

谢谢

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    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
    

    文件名中包含“-”可能有问题,所以我省略了。

    【讨论】:

      【解决方案2】:

      这是一些伪代码,您将如何在 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"
      

      【讨论】:

      • 感谢您的快速回复和帮助,但很抱歉这超出了我的想象。我正在专门寻找 VB 脚本帮助。
      • 发布 bash 作为对标记为 vbscript 的问题的答案似乎很奇怪。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多