The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
Dirpath as a variable
Discuss Dirpath as a variable in the Visual Basic Programming forum on Dev Shed. Dirpath as a variable Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 7th, 2012, 01:03 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 65
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
|
|
|
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
|

November 7th, 2012, 01:35 PM
|
|
|
|
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
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi
|

November 7th, 2012, 03:39 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 65
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
|
|
|
Thanks Doug G
testerV
|

November 8th, 2012, 03:19 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 65
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
|
|
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
|

November 8th, 2012, 11:15 PM
|
|
|
Quote: | 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?
|

November 9th, 2012, 02:39 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 65
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
|
|
|
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
|

November 10th, 2012, 01:41 AM
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|