Solved

Need help with Visual Basic Script

Posted on 2013-05-21
5
572 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
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
WebDevEM earned 500 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 51

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 51

Expert Comment

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

~bp
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now