Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How to prepend a filename with a pattern string?

Reply
 
Old 07-28-2009   #1 (permalink)
Ken Tucker


 
 

How to prepend a filename with a pattern string?

Assume I have an unknown filename (in a variable) with a path like

D:\myproject\data\myfilename.txt

Now I would like to prepend the filename with a string "aaa" so that
the new filename looks like

D:\myproject\data\aaamyfilename.txt

How can I do this inside a VBS script?

Ken


My System SpecsSystem Spec
Old 07-28-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: How to prepend a filename with a pattern string?


"Ken Tucker" <kenny23@xxxxxx> wrote in message
news:4a6f6e39$0$32670$9b4e6d93@xxxxxx-online.net...
Quote:

> Assume I have an unknown filename (in a variable) with a path like
>
> D:\myproject\data\myfilename.txt
>
> Now I would like to prepend the filename with a string "aaa" so that
> the new filename looks like
>
> D:\myproject\data\aaamyfilename.txt
>
> How can I do this inside a VBS script?
>
> Ken
>
You could locate the right-most backslash using the InStrRev function, then
insert "aaa" at this spot. Alternatively you could use the File System
Object like so:

sName = "D:\myproject\data\myfilename.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
WScript.echo oFSO.GetParentFolderName(sName) & "\aaa" &
oFSO.GetFileName(sName)


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
RE: searching for a pattern in a string!! VB Script
String pattern PowerShell
Capture a string of characters and use as filename. PowerShell
problems with $var | select-string -pattern $string -q PowerShell
Select-String pattern quirk??? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46