2013-05-30 33 views
0

冷冷的,我是新來的,希望你能幫上忙。 我是系統工程師,必須移動(複製)400個目錄中的500個文件夾。 文件夾名稱uniek GUID {f199a57f-fbee-411B-a70e-32619f87e6aa}命名將特定文件夾複製到新位置

是否有VB或者C#的方式來讓用戶輸入需要被COPYD文件夾的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 
+0

有可能是,但請告訴我們你已經嘗試過。 – pascalhein

+0

我試過這個,但注意到ha :-( – QuinCo

+0

請顯示一些代碼,所以我們可以找到它的問題 – pascalhein

回答

2
  1. 決定是否需要複製文件夾或文件
  2. 不要當虐待者 - 要求用戶輸入400個GUID到輸入框中!
  3. 使用dir在一個文本文件中創建的所有文件夾,500的列表
  4. 問問你asistent刪除100不會被複制
  5. 使用.bat或.VBS複製剩餘的400個文件夾
+0

嗨,感謝您的重播,我更想着有在一個txt或xls文件中有400個名字,並且用這個腳本來查看這個名字。現在,我不是一個scripter,所以不知道是否可以...... – QuinCo

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需要完整路徑。

0

首先,感謝您的幫助...

我們結束了使用兩個答案。我們讓數據庫管理員爲我們提供了必須移動的GUIS,在太多的txt文檔中抨擊這個GUIS,每天移植一次。我們使用的副本,而不是移動的,如果出現錯誤....這是我作出的腳本...

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 

請讓我知道是否有更好的方法,我喜歡學習:-)

謝謝

相關問題