将特定文件夹复制到新位置

时间:2013-05-30 09:18:38

标签: c# vbscript copy

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

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

感谢您的帮助......

此致 维姆

我尝试过Wat:

我试过这个,但注意到了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

3 个答案:

答案 0 :(得分:2)

  1. 决定是否需要复制文件夹或文件
  2. 不要成为虐待狂 - 要求用户在输入框中键入400 GUID!
  3. 使用dir创建文本文件中所有500个文件夹的列表
  4. 要求您保留删除不被复制的
  5. 使用.bat或.vbs复制剩余的400个文件夹

答案 1 :(得分: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需要有完整的路径。

答案 2 :(得分:0)

首先,谢谢你的帮助......

我们最终使用了两个答案。我们得到了数据库管理员给我们必须移动的GUIS,在4个txt doc中,每天迁移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

如果有更好的方法,请告诉我,我想学习: - )

由于