Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need help with Visual Basic Script

Posted on 2013-05-21
5
Medium Priority
?
608 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 58

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 58

Expert Comment

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

~bp
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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…
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 …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses

610 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