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 - Change filename using a wildcard

Reply
 
Old 04-17-2009   #1 (permalink)
touch0ph


 
 

Change filename using a wildcard

Hi. I'm trying to rename a desktop shortcut that the prefix will remain the
same but the suffix changes. How can I use a wildcard when refering to a
specific shortcut?

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set oShell = CreateObject( "WScript.Shell" )
ComputerName=oShell.ExpandEnvironmentStrings("%ComputerName%")

'This is where I included the * after Shortcut to as-sysa in the filename
objFSO.MoveFile "C:\Documents and Settings\All Users\Desktop\Shortcut to
a2-sysa*" , "C:\Documents and Settings\All Users\Desktop\A2-SYSA " &
ComputerName & ".lnk"

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


 
 

Re: Change filename using a wildcard


"touch0ph" <touch0ph@xxxxxx> wrote in message
news:76D67F25-85F4-4B45-AEE7-F0B8FF337195@xxxxxx
Quote:

> Hi. I'm trying to rename a desktop shortcut that the prefix will remain
> the
> same but the suffix changes. How can I use a wildcard when refering to a
> specific shortcut?
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> Set oShell = CreateObject( "WScript.Shell" )
> ComputerName=oShell.ExpandEnvironmentStrings("%ComputerName%")
>
> 'This is where I included the * after Shortcut to as-sysa in the filename
> objFSO.MoveFile "C:\Documents and Settings\All Users\Desktop\Shortcut to
> a2-sysa*" , "C:\Documents and Settings\All Users\Desktop\A2-SYSA " &
> ComputerName & ".lnk"
Your requirement "the prefix will remain the same but the suffix changes"
seems at odds with your example where you change
"Shortucut to a2-sysa*"
to
"as-sysaPC1.lnk"

It seems you wish to do four separate things:
1. Delete all leaders called "Shortcut to "
2. Take the remaining characters up to the full stop (which you do not spell
out)
3. Add the ComputerName
5. Add the string ".lnk".
Would this be correct? Why don't you do it manually?


My System SpecsSystem Spec
Old 04-17-2009   #3 (permalink)
Pegasus [MVP]


 
 

Re: Change filename using a wildcard


"touch0ph" <touch0ph@xxxxxx> wrote in message
news:F6B8C066-607C-4BC5-A0C0-C2AA1114C795@xxxxxx
Quote:

>
>
> "Pegasus [MVP]" wrote:
>
Quote:

>>
>> "touch0ph" <touch0ph@xxxxxx> wrote in message
>> news:76D67F25-85F4-4B45-AEE7-F0B8FF337195@xxxxxx
Quote:

>> > Hi. I'm trying to rename a desktop shortcut that the prefix will
>> > remain
>> > the
>> > same but the suffix changes. How can I use a wildcard when refering to
>> > a
>> > specific shortcut?
>> >
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> >
>> > Set oShell = CreateObject( "WScript.Shell" )
>> > ComputerName=oShell.ExpandEnvironmentStrings("%ComputerName%")
>> >
>> > 'This is where I included the * after Shortcut to as-sysa in the
>> > filename
>> > objFSO.MoveFile "C:\Documents and Settings\All Users\Desktop\Shortcut
>> > to
>> > a2-sysa*" , "C:\Documents and Settings\All Users\Desktop\A2-SYSA " &
>> > ComputerName & ".lnk"
>>
>> Your requirement "the prefix will remain the same but the suffix changes"
>> seems at odds with your example where you change
>> "Shortucut to a2-sysa*"
>> to
>> "as-sysaPC1.lnk"
>>
>> It seems you wish to do four separate things:
>> 1. Delete all leaders called "Shortcut to "
>> 2. Take the remaining characters up to the full stop (which you do not
>> spell
>> out)
>> 3. Add the ComputerName
>> 5. Add the string ".lnk".
>> Would this be correct? Why don't you do it manually?
>>
>>
> Yes, you have that correct. Why do something manually when you can
> automate
> it... Appending the computer name to the shorcut helps our helpdesk staff
> identify the name of the PC they're on when they have remote control over
> the
> PC or when the PC has no label.
Indeed: Automating a process can be a great productivity tool. Before
undertaking such a task one needs to be clear about a few things:
a) The complexity of the task
b) How much time is required to automate the process
c) Who does the work

In your case the following points seem relevant:
- Do you wish to process all items located on the desktop?
- Including those located in the "All Users" folder?
- Including those in subfolders?
- Do you have some code of your own that could serve as a framework, with
respondents filling the difficult details?
- What do you mean with "the PC has no label"? A blank "%ComputerName%"? I
thought this was impossible?


My System SpecsSystem Spec
Old 04-20-2009   #4 (permalink)
touch0ph


 
 

Re: Change filename using a wildcard



"Pegasus [MVP]" wrote:
Quote:

>
> "touch0ph" <touch0ph@xxxxxx> wrote in message
> news:F6B8C066-607C-4BC5-A0C0-C2AA1114C795@xxxxxx
Quote:

> >
> >
> > "Pegasus [MVP]" wrote:
> >
Quote:

> >>
> >> "touch0ph" <touch0ph@xxxxxx> wrote in message
> >> news:76D67F25-85F4-4B45-AEE7-F0B8FF337195@xxxxxx
> >> > Hi. I'm trying to rename a desktop shortcut that the prefix will
> >> > remain
> >> > the
> >> > same but the suffix changes. How can I use a wildcard when refering to
> >> > a
> >> > specific shortcut?
> >> >
> >> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> >> >
> >> > Set oShell = CreateObject( "WScript.Shell" )
> >> > ComputerName=oShell.ExpandEnvironmentStrings("%ComputerName%")
> >> >
> >> > 'This is where I included the * after Shortcut to as-sysa in the
> >> > filename
> >> > objFSO.MoveFile "C:\Documents and Settings\All Users\Desktop\Shortcut
> >> > to
> >> > a2-sysa*" , "C:\Documents and Settings\All Users\Desktop\A2-SYSA " &
> >> > ComputerName & ".lnk"
> >>
> >> Your requirement "the prefix will remain the same but the suffix changes"
> >> seems at odds with your example where you change
> >> "Shortucut to a2-sysa*"
> >> to
> >> "as-sysaPC1.lnk"
> >>
> >> It seems you wish to do four separate things:
> >> 1. Delete all leaders called "Shortcut to "
> >> 2. Take the remaining characters up to the full stop (which you do not
> >> spell
> >> out)
> >> 3. Add the ComputerName
> >> 5. Add the string ".lnk".
> >> Would this be correct? Why don't you do it manually?
> >>
> >>
> > Yes, you have that correct. Why do something manually when you can
> > automate
> > it... Appending the computer name to the shorcut helps our helpdesk staff
> > identify the name of the PC they're on when they have remote control over
> > the
> > PC or when the PC has no label.
>
> Indeed: Automating a process can be a great productivity tool. Before
> undertaking such a task one needs to be clear about a few things:
> a) The complexity of the task
> b) How much time is required to automate the process
> c) Who does the work
>
> In your case the following points seem relevant:
> - Do you wish to process all items located on the desktop?
> - Including those located in the "All Users" folder?
> - Including those in subfolders?
> - Do you have some code of your own that could serve as a framework, with
> respondents filling the difficult details?
> - What do you mean with "the PC has no label"? A blank "%ComputerName%"? I
> thought this was impossible?
>
>
The script will be used by a team of about 12 PC techs on about 2500 desktop
PC's and laptops. I'm trying to cut down the time they have to spend doing
mundane, repititve tasks that can be done automatically.
Quote:

> Do you wish to process all items located on the desktop?
No, not all. There are seven desktop icons I'd like to rename. They will
always start with 1 of 2 naming conventions: "Shortcut to ......" or
"A2-SYSA"

Including those located in the "All Users" folder?
The icons are all in the "All Users\Desktop" folder. I don't need to go
through all the user profiles.

Do you have some code of your own that could serve as a framework, with
respondents filling the difficult details?
We have a naming convention that I would


What do you mean with "the PC has no label"? A blank "%ComputerName%"? I
thought this was impossible? A label, like a physical label on the
computer chassis.


What I'm asking for is a reference or example of code I could use to rename
a desktop shortcut, on the All Users\Desktop, where I know the first portion
of the shortcut name, but the ending is different. I figured a wildcard
charcater would work best but if there's another method that would be great
too!
TIA!
My System SpecsSystem Spec
Old 04-20-2009   #5 (permalink)
Pegasus [MVP]


 
 

Re: Change filename using a wildcard


"touch0ph" <touch0ph@xxxxxx> wrote in message
news:3049D6F9-2914-418B-B94F-903D6D87DCA2@xxxxxx
Quote:

>
>
> "Pegasus [MVP]" wrote:
>
Quote:

>>
>> "touch0ph" <touch0ph@xxxxxx> wrote in message
>> news:F6B8C066-607C-4BC5-A0C0-C2AA1114C795@xxxxxx
Quote:

>> >
>> >
>> > "Pegasus [MVP]" wrote:
>> >
>> >>
>> >> "touch0ph" <touch0ph@xxxxxx> wrote in message
>> >> news:76D67F25-85F4-4B45-AEE7-F0B8FF337195@xxxxxx
>> >> > Hi. I'm trying to rename a desktop shortcut that the prefix will
>> >> > remain
>> >> > the
>> >> > same but the suffix changes. How can I use a wildcard when refering
>> >> > to
>> >> > a
>> >> > specific shortcut?
>> >> >
>> >> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> >> >
>> >> > Set oShell = CreateObject( "WScript.Shell" )
>> >> > ComputerName=oShell.ExpandEnvironmentStrings("%ComputerName%")
>> >> >
>> >> > 'This is where I included the * after Shortcut to as-sysa in the
>> >> > filename
>> >> > objFSO.MoveFile "C:\Documents and Settings\All
>> >> > Users\Desktop\Shortcut
>> >> > to
>> >> > a2-sysa*" , "C:\Documents and Settings\All Users\Desktop\A2-SYSA " &
>> >> > ComputerName & ".lnk"
>> >>
>> >> Your requirement "the prefix will remain the same but the suffix
>> >> changes"
>> >> seems at odds with your example where you change
>> >> "Shortucut to a2-sysa*"
>> >> to
>> >> "as-sysaPC1.lnk"
>> >>
>> >> It seems you wish to do four separate things:
>> >> 1. Delete all leaders called "Shortcut to "
>> >> 2. Take the remaining characters up to the full stop (which you do not
>> >> spell
>> >> out)
>> >> 3. Add the ComputerName
>> >> 5. Add the string ".lnk".
>> >> Would this be correct? Why don't you do it manually?
>> >>
>> >>
>> > Yes, you have that correct. Why do something manually when you can
>> > automate
>> > it... Appending the computer name to the shorcut helps our helpdesk
>> > staff
>> > identify the name of the PC they're on when they have remote control
>> > over
>> > the
>> > PC or when the PC has no label.
>>
>> Indeed: Automating a process can be a great productivity tool. Before
>> undertaking such a task one needs to be clear about a few things:
>> a) The complexity of the task
>> b) How much time is required to automate the process
>> c) Who does the work
>>
>> In your case the following points seem relevant:
>> - Do you wish to process all items located on the desktop?
>> - Including those located in the "All Users" folder?
>> - Including those in subfolders?
>> - Do you have some code of your own that could serve as a framework, with
>> respondents filling the difficult details?
>> - What do you mean with "the PC has no label"? A blank "%ComputerName%"?
>> I
>> thought this was impossible?
>>
>>
> The script will be used by a team of about 12 PC techs on about 2500
> desktop
> PC's and laptops. I'm trying to cut down the time they have to spend
> doing
> mundane, repititve tasks that can be done automatically.
>
Quote:

>> Do you wish to process all items located on the desktop?
> No, not all. There are seven desktop icons I'd like to rename. They
> will
> always start with 1 of 2 naming conventions: "Shortcut to ......" or
> "A2-SYSA"
>
> Including those located in the "All Users" folder?
> The icons are all in the "All Users\Desktop" folder. I don't need to go
> through all the user profiles.
>
> Do you have some code of your own that could serve as a framework, with
> respondents filling the difficult details?
> We have a naming convention that I would
>
>
> What do you mean with "the PC has no label"? A blank "%ComputerName%"? I
> thought this was impossible? A label, like a physical label on the
> computer chassis.
>
>
> What I'm asking for is a reference or example of code I could use to
> rename
> a desktop shortcut, on the All Users\Desktop, where I know the first
> portion
> of the shortcut name, but the ending is different. I figured a wildcard
> charcater would work best but if there's another method that would be
> great
> too!
> TIA!
Here you have some skeleton code. You'll have to expand it to suit your
needs and make it robust, e.g. by doing this:
- Add wildcard capability
- Check if the file exists
- Check if it can be renamed
- Add user feedback

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oWshShell = CreateObject("WScript.Shell")
sOldName =
oWshShell.ExpandEnvironmentStrings("%AllUsersProfile%\Desktop\Shortcut to
Explorer.lnk")
sNewName =
oWshShell.ExpandEnvironmentStrings("%AllUsersProfile%\Desktop\Explorer
%ComputerName%.lnk")
oFSO.MoveFile(sOldName, sNewName)


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Run Exe From a CD with wildcard VB Script
filename change PowerShell
filename change General Discussion
how to get the file name from using a wildcard VB Script
Change Filename Settings for Recorded TV Vista General


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