Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
This is an annoying problem. I have a text file containing full path and filenames to files I need to copy. Each on its own line. Used replace in wordpad to make a Batch (.BAT) file to copy the files. For some reason though, I seemed to be unable to access the directory from DOS prompt (It's some network drive BTW). Instead, I made a VB-script that looped though the file and did a LINE INPUT and then used a copy function. There is a problem with windows scripting host on this computer, so my program hung on this line:
Open "test.txt" For Input As #1
.. The scripting host didn't like FOR, so I guess it's just something wrong with the scripting host.
It's a really annoying problem, because I would have fixed it some time ago, if I only had VB on this computer, or if Windows Scripting Host worked or access from cmd.exe.I need n00b Help ;P

Well... I think I will go with your initial attempt on the BAT file on this one. Too much VB going on here these days...
To assign a drive letter to your network drive use the NET USE command (line 2 of script). Then just do your normal DOS commands for copying or other operations you need. Then delete the drive letter assigned to your mapped network drive using the /DELETE option on the NET USE command (line 5 of script)
Beowulf is my system name, MyShare is the directory I want to map as a drive. username is a system variable containing my name for authorization.
---------- SCRIPT -------------------
echo off
NET USE X: \\Beowulf\MyShare /USER:%username%
XCOPY X:\test.txt C:\BIN
DEL X:\test.txt
NET USE X: /DELETE
pause-----
That should work out for you... Let me know.
Infinite Recursion

In addition, it might be that Windows didn't like long file/folder names with spaces in them. Try enclosing the full path in speech marks:
"c:\program files\another folder\a big file.doc"

You are assuming too much. if you use:
open FileName for input as #1
then the file id 1 MUST be available (which may not always be the case)
try this:
Dim FileID As Long
FileID = FreeFile()
Open "test.txt" For Input As #FileIDthen read the file and stuff.
One last note: I haven't done a ton of VBScripting (as far as VBS) but in some flavors of VB (such as ASP pages) you cannot Dim variables AS ANYTHING, not can you use NEXT {Variable} in those cases you have to do this:
'Dim Example
Dim FileID' For Example
For T = 0 To 100
Next ' Leave off TOh and since I mentioned that, I should also mention that within ASP you cannot use
Open FileName For Input As #FileID
You have to use an FSO
Dim FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
FSO.OpenTextFile "test.txt", 1' do stuff with the file
Set FSO = Nothingand this will only work if the server allows you to A) Create Objects and B) Create a FileSystemObject (which some don't allow since you can also do FSO.DeleteFolder)
Hope this helps you some,
Chi Happens

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |