#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    86
    Rep Power
    3

    Dirpath as a variable


    Hi guys,
    Iím trying to make a network Dir and local Dir identical,
    If a folder in a local Dir does not exist I want to create it.
    Iím planning to do some other stuff with the script later.

    I use Network and Local ďDirpathĒ as a variable but it does not work, apparently I cannot pass it is as variable.
    Any idea why?
    Thanks, testerV

    Code:
    Dim Mydirtosplit1,MyArray,MyDrivle_Letter,MynewDrive   
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("C:\Sub_Dirsize.txt", True)
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
    set objFolder = objFSO.GetFolder("O:\Test\File_test")
    
    for Each folder in objFolder.SubFolders
        On Error Resume Next
        size = folder.size 
     Mydirtosplit1 = folder           ' My network Dir '
     MyArray = Split(Mydirtosplit1, ":")
     Myarray(0) = "C"
     MynewDrive = Join(MyArray,":")    'My local Dir '
    
    Const OverWriteFiles = True
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    If Not objFSO.FolderExists("MynewDrive") then 
    objFSO.CopyFolder "Mydirtosplit1" , "MynewDrive" , OverWriteFiles
    End if
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    Take out the on error resume next statement and maybe you'll see an error message that's causing your problem.

    Another suggestion, there are lots of sync programs that will do what you are apparently trying to code. In linux land I use a program called rsync to synchronize directories between network machines. Microsoft has a free synctoy program that may work for you.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    86
    Rep Power
    3
    Thanks Doug G
    testerV
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    86
    Rep Power
    3
    Hi Guys,
    I really appreciate your ideas to use synctoy or rsync, I think I'll use synctoy but I still have one more question.
    I just found my script (part of the script) will run if I call it from CMD but doesn't run if I execute it. As you see I'm not that good with VB and this is very strange for me.
    Thanks, testerV
    Code:
      Dim Mydirtosplit1,MyArray,MyDrivle_Letter,MynewDrive
       Mydirtosplit1 = "C:\TEMP"
       MynewDrive    = "C:\TEST" 
         Const OverWriteFiles = True
         Set objFSO = CreateObject("Scripting.FileSystemObject")
    
         If Not objFSO.FolderExists("MynewDrive") then 
         objFSO.CopyFolder Mydirtosplit1 , MynewDrive , OverWriteFiles
         End if
     
         WScript.Quit
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    I just found my script (part of the script) will run if I call it from CMD but doesn't run if I execute it
    What do you mean by this? How are you invoking your script?
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    86
    Rep Power
    3
    Doug, thank you for looking in to it!

    When I call my script from CMD:
    C:\Users\altmthv>c:\scripts\myscript1.vbs
    It runs and copies, folder Mydirtosplit1 to MynewDrive
    Mydirtosplit1 = "C:\TEMP"
    MynewDrive = "C:\T2000"

    If I execute the script (double click on it) nothing coped.
    testerV
  12. #7
  13. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,443
    Rep Power
    4539
    Windows may have security settings that prevent you from running scripts by double-clicking, or maybe the .vbs extension isn't associated properly with the vbscript executable.

    If you're on vista or windows 7 try running the script as an administrator (right click on the script then choose 'run as administrator. If that works, run windows explorer itself as administrator and see if double-clicking the script works.

    In any case, it doesn't sound to me like your vb code is the problem.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester

IMN logo majestic logo threadwatch logo seochat tools logo