?
Solved

Need help with Visual Basic Script

Posted on 2013-05-21
5
Medium Priority
?
599 Views
Last Modified: 2013-05-22
I have a script that replaces characters in file names for a folder and its sub-folders.  I have attached the file.

where I have:

set rootFolder = objFSO.GetFolder("C:\Copy\temp\New Folder")

I would like the path ("C:\Copy\temp\New Folder") to be the "current directory" that the script is located in, rather than having an absolute folder path there as it is now.

If that isn't possible, then I would like the user to be able to input that path using a dialog box.
0
Comment
Question by:tommy777
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
WebDevEM earned 2000 total points
ID: 39185121
Hi,

You can get the current folder with this code -
currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))

Open in new window

which you can then use instead of "c:\copy\temp\New Folder" like so:
currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
set rootFolder = objFSO.GetFolder(currentDirectory) 

Open in new window


WebDevEM
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 39185267
Be careful with that, it may be what you want, but I prefer the following.  The difference is, the first solution will return the path to the location of the script itself, not the current directory.  The below approach gets the current directory.  I often have the script in a common scripts folder, not the current directory I'm working in, so prefer this approach.

Set objFSO = CreateObject("Scripting.FileSystemObject")
strCurDir = objFSO.GetAbsolutePathName(".")
Wscript.Echo strCurDir

Open in new window

~bp
0
 

Author Comment

by:tommy777
ID: 39185281
Thanks that works.  The other problem I am having is that the last two functions don't seem to work together.  The last function works (the " " is replaced with "_".  The previous function where the "#" is to be replaced with "_" seems to be skipped over.  

I have attached the file.
0
 
LVL 56

Expert Comment

by:Bill Prew
ID: 39187939
Hmmm, did you mean to split points?

~bp
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question