I have vbscript application that run in a server and I tried run that application in my local computer. The problem is I want to create a text file in server directory but I always end up with an error something like "disk is not ready". When I check, it is because in my local computer, there is only 1 partition Drive C: and for some reason the application try to make the textfile in my local directory. And if change the path to drive C: it works and the file is existed in my local directory. So what am I doing wrong? I want the text file is created in server directory.
Here's part of my code :
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("D:\tesfolder\SomeText.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close
Set MyFile = Nothing
Set fso = Nothing
please help me
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("\\127.0.0.1\C$\SomeText.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close
The above needs Admin because it uses the Admin only share (present on all computers) c$ and writes to the root of C: drive.
The format is
\\ServerName(orIP)\ShareName\Folder\File.ext
An admin would
\\Computer\D$\tesfolder\SomeText.txt
For a user substitute their share name for D$.
Related
Scenario:
I am running my VBScript in 'Test complete' which is a Automation Testing Tool from a Virtual Machine.
My scripts are residing in the Folder E:\TC from VM\TC (in physical Machine).
I have mapped my VM to this shared folder, so from VM my directory structure is: Z:\E\TC from VM\TC.
If I put the code here - then it displays the path correctly - but if I put this code in a function and call the function it displays a different path. WHY, and how I can rectify it?
Dim fso, ShowAbsolutePath, objFile, GetParentDir
Dim strFile : strFile = "..\..\Variables.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
ShowAbsolutePath = fso.GetAbsolutePathName(strFile)
Log.Message("The File is:"&ShowAbsolutePath)
GetParentDir = fso.GetParentFolderName(ShowAbsolutePath)
Log.Message("The parent directory of the File is:"&GetParentDir)
Set objFile = fso.GetFile(ShowAbsolutePath)
Output :
The File is:Z:\E\TC from VM\TC\Variables.txt
The parent directory of the File is:Z:\E\TC from VM\TC
Output (if I put this code in function and then call the function):
The File is:Z:\E\TC from VM\TC\MMSDemo\MMSDemo
The parent directory of the File is:Z:\E\TC from VM\TC\MMSDemo
Why the difference?
I am just passing to the function the variable strFile where strFile = "..\..\Variables.txt".
.GetAbsolutePathName() combines the current directory with the relative path given as parameter without regard to existence of files or folders:
>> WSCript.Echo goFS.GetAbsolutePathName("..\nosuchdir\nosuchfile.txt")
>>
E:\trials\SoTrials\answers\27749208\nosuchdir\nosuchfile.txt
So the given parameter must be part of the result. If you get
The File is:Z:\E\TC from VM\TC\MMSDemo\MMSDemo
The parent directory of the File is:Z:\E\TC from VM\TC\MMSDemo
then .GetAbsolutePathName() was not called with "....\Variables.txt", but with an empty value/string. Do you use "Option Explicit"?
So im writing a script that drops a file folder then moves that file to the folder it dropped it self. Well the folder drops fine but the file wont move. Can some see whats wrong with my code? Or give me a better way to move the file. I also get no error message about trying to move the file.
Dim folder,fso,filsys,C
Set fso = CreateObject("Scripting.filesystemObject")
Set folder = fso.GetSpecialFolder(1)
Set wshshell = CreateObject("wscript.shell")
Set filesys = CreateObject("scripting.filesystemobject")
Set objfso = CreateObject("Scripting.filesystemObject")
Set c = fso.GetFile(Wscript.scriptFullname)
On Error Resume NEXT
Set objFolder = objFSO.CreateFolder("C:\55egr932ntn7mk23n124kv1053bmoss5")
If Err.Number<>0 Then
End If
WScript.Sleep 3000
C.Move ("C:\552ntn7mk23n124kv1053bmoss5\File.exe") (folder&"\File.exe")
And I have a program I use that turns the VBS into and EXE so you see the "file.exe" which really is the .VBS itself
I'm not familiar with this syntax, but the line below looks like it's expecting the folder variable to be a string.
C.Move ("C:\552ntn7mk23n124kv1053bmoss5\File.exe") (folder&"\File.exe")
Earlier in code it looks as though you're setting folder as an object.
Set folder = fso.GetSpecialFolder(1)
You might not get the error you mentioned in your comment if you convert folder to a string.
~~
Another thing to try is the following code:
Set fso = CreateObject("Scripting.filesystemObject")
Set folder = fso.GetSpecialFolder(1)
Alert (folder&"\File.exe")
(I'm not sure if it's "Alert" or "Msgbox" or something else.) That test will show you whether the file path makes sense. If you get an error on line 3 of that test, try converting folder to a string before your Alert (or Msgbox).
I have a folder which is on a network like \\server\contents\tasks and I want to access this folder.
I am getting a "path not found" exception. What am I doing wrong here:
Dim FolderPath
FolderPath = "\\server\contents\tasks"
set FSO = CreateObject("Scripting.FileSyatemObject")
FSO.GetFolder(FolderPath)
Thanks
Edit: I found this post which answers the same thing I am trying to achieve, but the issue is I am getting an error the network share is no longer available. What I have is a local folder as a shared folder and mapped as \\servername\contents\tasks but it gives me the above error.
Edit: I was pointing at the wrong folder.
Now I have another issue trying to open a text file in the network folder. It is able to create a folder at the network path but throwing error while reading a text file in the network folder. Is there something else that needs to be done?
Set FSO = CreateObject("Scripting.FileSystemObject")
strOutputPath = strOutput1 --this is a network path
Set txsOutput = FSO.CreateTextFile(strOutputPath)
Set f = FSO.OpenTextFile(strInput1)
Open the network folder using explorer.exe and pass the location of the folder as a parameter (in this example it's sPath storing the folder path)
Example:
sPath = "\\somedrive.somecompany.ie\software"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "explorer /n," & sPath, 1, False
Terms and conditions: username and password privileges already setup for acccess to the network folder.
I've been trying to make a little VBS that gets all Home Directories on a Server and moves them to a different place. Little Example
C:\homefolders\test_person
C:\homefolders\test_person\old_home
Here is what I got so far, but the moving part doesn't work...
Call ListFolderContents("C:\Windows\System32\Drivers")
Sub ListFolderContents(path)
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)
Msgbox folder.path
For each item in folder.SubFolders
ListFolderContents(item.Path)
Next
set folder = Nothing
set fs = Nothing
End Sub
Assuming there's no problem with permissions:
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)
folder.Move newPath
Cheers
I want to unzip a .zip file using VBScript, only it's always a new computer with no external applications on it. Now I know Windows XP and 2003 have an internal .zip folder option, so I guess I can use it via VBScript in order to extract the file.
How do I do it?
I tried:
Set objShell = CreateObject("Shell.Application")
Set SrcFldr = objShell.NameSpace(fileName)
Set DestFldr = objShell.NameSpace(appDir)
DestFldr.CopyHere(SrcFldr)
Which didn't work.
What could be the problem?
Just set ZipFile = The location of the zip file, and ExtractTo = to the location the zip file should be extracted to.
'The location of the zip file.
ZipFile="C:\Test.Zip"
'The folder the contents should be extracted to.
ExtractTo="C:\Test\"
'If the extraction location does not exist create it.
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
fso.CreateFolder(ExtractTo)
End If
'Extract the contants of the zip file.
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing