Solved

Need help with Visual Basic Script

Posted on 2013-05-21
5
587 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 54

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 54

Expert Comment

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

~bp
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 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…

726 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