Results 1 to 5 of 5

Thread: Folder Collection Question

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    5

    Folder Collection Question

    Is there a way to parse a share or workstation and only collect specific folder names in VB? I had thought i would of been able to do it in robocopy, the same way you include files option, but it does not look like you can target directories.

    i had been at it for a few weeks before i figured out you cannot do it in robocopy... if anyone could alteast point me in the right direction i would greatly appreciate it.

  2. #2
    New Member
    Join Date
    Feb 2017
    Posts
    13

    Re: Folder Collection Question

    I'm quite sure there is, but I'd need more specifics of exactly what you need to do. I ran across a function yesterday or the day before that would return your entire directory structure in an array if that's what you needed, although it did more than I needed for the project I'm doing as I only needed the subdirectories only of specific directory and not any other subdirectory up the tree. Kinda like saying Dir *. and getting your directories. Although I'm not sure either of those functions are what you're looking for. with VBScript, you can pretty much do most anything your hearts desire if you have the coding skill to get it done. Again, I'd need more detailed information to be able to answer any further. Although knowing if it's a mapped drive or not (assuming your meant a drive across the network.) Mapped is easy, just treat it as another drive of your own system. Not mapped, I'd have to look up. I don't access network drives in the fashion very often, but that can be done too.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2014
    Posts
    5

    Re: Folder Collection Question

    Sorry about the confusion with my initial description. What I am looking to do is the following:
    Parse the source location for specified folder names ex “caffeine, mountain dew, sprite” and when it finds the folders the script will copy the folders and their contents. For the target location the files should reflect the folder structure they were copied from.

  4. #4
    New Member
    Join Date
    Feb 2017
    Posts
    13

    Re: Folder Collection Question

    Quote Originally Posted by friendlyvission View Post
    Sorry about the confusion with my initial description. What I am looking to do is the following:
    Parse the source location for specified folder names ex “caffeine, mountain dew, sprite” and when it finds the folders the script will copy the folders and their contents. For the target location the files should reflect the folder structure they were copied from.
    Yes, it can be done.

    If I understand you correctly, you want to search a folder tree beginning with a particular folder. See if that folder exists, if it does, then copy the contents of the folder somewhere else, although I'm still confused on the target location because it sounds like you want another copy right where they sit or you're thinking of it as you would a batch file and can copy *.* . which would be the current directory. It's easiest to know exactly where you want the files to go. Maybe that can be done, but that isn't how I would do it. Usually I know exactly where I want the files to go and then search the tree and copy them specifically where I want them to go, even if I'm making a new tree dynamically, I account for that in the code, but it's still a specific location to copy them to.

    Do you have any code done on it yet? I can come up a generic search tree and copy, but without knowing the detailed specifics, it's hard to know where to start the search at or where to copy them to.

  5. #5
    New Member
    Join Date
    Feb 2017
    Posts
    13

    Re: Folder Collection Question

    I'm not sure if this helps, but this is what it looks like to copy in vbScript.

    Code:
    ObjFSO.CopyFile FileToSave, TPPBackupPath & "\TPP_GAME_DATA1.B" & LatestIpadModified
    In this case FileToSave is a variable that contains the whole path to the file I want to copy including the file name. TPPBackupPath is the path I want to copy to \TPP_GAME_DATA1.B is a partial file name and LatestIpadModified is a variable containing 01,02,03 etc, to give the whole filename which is TPP_GAME_DATA1.B01 or whichever name I am naming it, which I have 100 other lines of code determining what it will be named because it's based on other files and other backups.

    Generically, the way to copy a file is:

    Code:
    Dim ObjFSO
    Set ObjFSO = CreateObject("Scripting.FileSystemObject")
    
    ObjFSO.CopyFile <FileToCopyWithFullPath>, <PathToDestination>
    Although you'll need other code for searching the directory tree for your criteria.

    Edit:

    In hindsight, you might be able to do something like this......

    Code:
    Dim WSHShell
    Set WSHShell = Wscript.CreateObject("Wscript.Shell")
    
    Dim ObjFSO
    Set ObjFSO = CreateObject("Scripting.FileSystemObject")
    
    ObjFSO.CopyFile <FileToCopyWithFullPath>, WSHShell.CurrentDirectory
    Although I still think it's best to know the specific path you want to copy to because that will copy to where ever you run the script from. It's still better to copy to a known location, even if that location is being created dynamically.
    Last edited by rjwebgraphix; Feb 28th, 2017 at 06:00 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width