QuinCo
QuinCo

Reputation: 1

Copy specific folders to new location

Firs of, i am new here and hope you can help. I am a systen engeneer and have to move (copy) 400 out of 500 folder's in a directory. The folder names are uniek GUID {f199a57f-fbee-411b-a70e-32619f87e6aa} naming

Is there a VB or C# way to have the user input the 400 names of the folders that need to be copyd and let the scrip search them and copy the folders too a new location?

Thank you for your help...

Regards, Wim

Wat i tried:

I tried this, but noting 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

Upvotes: 0

Views: 233

Answers (3)

QuinCo
QuinCo

Reputation: 1

First of, thank's for all your help...

We ended up using both answers. We got the DB admins to give us the GUIS's that have to be moved, slapt that in too 4 txt doc's, 1 for everyday of the migration. We used copy, not move for if something goes wrong.... here is the script i made...

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

Please let me know if there is a better way, i like to learn :-)

Thanks

Upvotes: 0

Dan K
Dan K

Reputation: 409

This is simple to do. Example script that will read a text file and move them is as fallows;

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."

The list_of_folders.txt needs to have full paths.

Upvotes: 1

Ekkehard.Horner
Ekkehard.Horner

Reputation: 38775

  1. Decide whether you need to copy folders or files
  2. Don't be a sadist - asking a user to type 400 GUIDs into an InputBox!
  3. Use dir to create the list of all 500 folder in a text file
  4. Ask your asistent to delete the 100 not to be copied
  5. Use a .bat or .vbs to copy the 400 remaining folders

Upvotes: 2

Related Questions