0

首先,我是新来的,希望您能提供帮助。我是一名系统工程师,必须从目录中的 500 个文件夹中移动(复制)400 个。文件夹名称为 uniek GUID {f199a57f-fbee-411b-a70e-32619f87e6aa} 命名

是否有 VB 或 C# 方法让用户输入需要复制的文件夹的 400 个名称,让脚本搜索它们并将文件夹复制到新位置?

谢谢您的帮助...

问候, 维姆

我试过了:

我试过这个,但注意到hapens :-(

Sub CopySomeFolder()
    Dim FSO, sourceFolder, currentFile, filesInSourceFolder
    Dim strSourceFolderPath
    Dim strDestinationFolderPath
    Dim strUserInput
    Set FSO = CreateObject("Scripting.FileSystemObject")

    ' Figure out which folder to copy from where to where
    strUserInput = InputBox("Please enter name of file to copy.")
    strSourceFolderPath = "M:\"
    strDestinationFolderPath = "M:\"

    Set sourceFolder = FSO.GetFolder(strSourceFolderPath)
    Set filesInSourceFolder = sourceFolder.Files

    ' Look at all folders in source folder. If name matches,
    ' copy to destination folder.
        For Each currentFile In filesInSourceFolder
        If currentFile.Name = strUserInput Then
            currentFile.Copy (FSO.BuildPath(strDestinationFolderPath, _
                currentFile.Name))
        End If
    Next

End Sub
4

3 回答 3

2
  1. 决定是否需要复制文件夹或文件
  2. 不要成为虐待狂 - 要求用户在 InputBox 中输入 400 个 GUID!
  3. 用于dir在文本文件中创建所有 500 个文件夹的列表
  4. 让你的助手删除100个不要被复制的
  5. 使用 .bat 或 .vbs 复制剩余的 400 个文件夹
于 2013-05-30T10:00:06.437 回答
1

这很简单。将读取文本文件并移动它们的示例脚本如下所示;

Const ForReading = 1
Const list = "c:\list_of_folders.txt"
Const destination = "c:\temp\"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim folders : Set folders = fso.OpenTextFile(list, ForReading)
Dim folder
Do Until folders.AtEndOfStream
  folder_loc = folders.ReadLine
  If fso.FolderExists(folder_loc) Then
    Set folder = fso.GetFolder(folder_loc)
    folder.move(destination)
  End If
Loop
Wscript.echo "Operation completed."

list_of_folders.txt 需要有完整路径。

于 2013-05-30T13:37:58.100 回答
0

首先,谢谢大家的帮助...

我们最终使用了这两个答案。我们让 DB 管理员给我们必须移动的 GUIS,在 4 个 txt 文档中拍打,1 个用于每天的迁移。我们使用副本,如果出现问题,不要移动......这是我制作的脚本......

Dim arrFileLines()
 i = 0
set filesys = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserInput = InputBox ("Pathe to TXT file containing the folder names: " & _
                        chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
                        "\\Servername\C$\Program Files)")
strUserInputFrom = InputBox("Enter the directory path to the folders u want to copy: " & _
                        chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
                        "\\Servername\C$\Program Files)")
strUserInputTo = InputBox("Enter the destination folder: " & _
                        chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
                        "\\Servername\C$\Program Files)")
Set objFile = objFSO.OpenTextFile(strUserInput, 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
 arrFileLines(i) = objFile.ReadLine
 i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
 Wscript.echo strUserInputFrom&"\"&arrFileLines(l) &" copy to " & strUserInputTo&"\"
 filesys.CopyFolder strUserInputFrom&"\"&arrFileLines(l), strUserInputTo&"\"

Next

请让我知道是否有更好的方法,我喜欢学习:-)

谢谢

于 2013-05-31T07:54:12.093 回答