Solved

Need help with Visual Basic Script

Posted on 2013-05-21
5
581 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 53

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 53

Expert Comment

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

~bp
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

825 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