Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current directory....

Status
Not open for further replies.

Fherrera

Technical User
May 11, 2004
129
CA
Hi, this is probably super simple but i'm still a newb..

Anyway, i'm trying to get the current directory that the VBScript is running from... I saw something akin to:

Server.MapPath(".")

but umm.. I'm not doing this for ASP or any web stuff, i'm trying to copy files from the current directory ..it's just I can't get the current directory...


Function CopyFile(sFilePath,sFileName,bOverwrite)
Dim fso, folder

Set fso = CreateObject("Scripting.FileSystemObject")

If fso.FileExists(sFilePath, sFileName) Then
WScript.Echo "She exists!!"
Else
' WScript.Echo "She no exists :<"
End If
End Function

Call CopyFile("\","blah.txt",True)

---

Is about what I have..except the "\" doesnt' work neither does "." and i'm not sure what else to try....

Thx

Frank
 
This is what I most often use:
Code:
Function GetWorkingDir()
	Dim arrParts, strDir, i
	
	arrParts = Split(WScript.ScriptFullName, "\")
	For i=0 to UBound(arrParts) - 1
		strDir = strDir & arrParts(i) & "\"
	Next
	GetWorkingDir = strDir
End Function

There are better functions, but sometimes I have had various issues with them.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Hrm, that works great Thanks.

Now, it doesn't seem to recognize the current file in the folder... which is somehting like:

Overview of Leaks - Someplace.xls

Any idea's why that might be? An echo of the path and filename looks exactly as it should..but the code:

If fso.FileExists(sFilePath & sFileName) Then
WScript.Echo "She exists!!"
Else
WScript.Echo "She no exists :<"
End If

Keeps returning She no exists :<

Frank
 
If you put:
WScript.Echo sFilePath & sFileName
Right above:
If fso.FileExists(sFilePath & sFileName) Then
What does it output?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Well..-cough- umm.. Hehe.. sorry about that.. I had changed the original file I was looking for and forgot to make a copy of the original before I did that.. (ie. I added the date to the name)

Well..hrm.. let's all forget that silly question then.

Thanks again Tom

Frank
 
Hello all,

The current directory is avail for wsh5.6 like this.
Code:
wscript.echo createobject("wscript.shell").workingdirectory
regards - tsuji
 
Tsuji, are you talking about the CurrentDirectory property of the WshShell object ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello PHV,

Yes. But after going through roughly the thread, still does not quite know whether it helps. It doesn't more likely. I guess I do not understand the problem and the setting! That's frustrating.

regards - tsuji
 
PHV, I now see what you mean. Sorry! It is this.
Code:
wscript.echo createobject("wscript.shell").currentdirectory   '[red]_correction_[/red]
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top