I have a file [pathfilename.???] The file extension must be changed between .ini and .len relative to my needs.
I need a script that will tell me the current file extension.
Can a condition be added to allow me to change the extension to the other extension if appropriate to my current need?
Thanks.
![]() |
There are isolated problems with current patches, but they are well-known and documented on this site. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
need vbscript to determine file extension
Home » Forums » Developers, developers, developers » DevOps Lounge » need vbscript to determine file extension
- This topic has 11 replies, 5 voices, and was last updated 12 years, 8 months ago.
AuthorTopicWSskipro
AskWoody LoungerOctober 29, 2011 at 7:17 pm #479781Viewing 5 reply threadsAuthorReplies-
WSjscher2000
AskWoody LoungerOctober 30, 2011 at 12:18 pm #1304535The Windows Scripting library’s FileSystemObject provides access to the full file name (Name Property (FileSystemObject)), and also the option to rename the file.
Are you running your code at a system prompt or from another host (e.g., an Office application, an ASP page)?
-
WSskipro
AskWoody LoungerOctober 31, 2011 at 10:08 am #1304651I am running simple .vbs scripts.
File name is either bootnow.ini or .len. What I would like is to return just the extension [preferably] or if necessary the entire name and give me an opportunutiy to change it to the other. If extension is .ini, I need a way to change it to .len, if .len, I need an option to change it to .ini
My thought is an if/then argument
Ex:
Current extension is .ini [or .len]
{or current name is Bootnow.ini}
Would you like to change extension to .len? [or .ini]
{change name to bootnow.len}Press “Y” or YES
“Extension changed”
for NO
[[or any other means to select choice]]
-
-
WSjscher2000
AskWoody LoungerOctober 31, 2011 at 3:32 pm #1304778This is an example using an arbitrary folder name. Not the most elegant code, but seems to work in a quick test:
Code:Dim fso, fname, f Set fso = WScript.CreateObject("Scripting.FileSystemObject") fname = "c:attachbootnow.ini" If fso.FileExists(fname) Then If MsgBox("Rename bootnow.ini to bootnow.len?", vbYesNo+vbQuestion) = vbYes Then Set f = fso.GetFile(fname) f.Name = Left(f.Name, InStrRev(f.Name, ".")) & "len" End If Else fname = "c:attachbootnow.len" If fso.FileExists(fname) Then If MsgBox("Rename bootnow.len to bootnow.ini?", vbYesNo+vbQuestion) = vbYes Then Set f = fso.GetFile(fname) f.Name = Left(f.Name, InStrRev(f.Name, ".")) & "ini" End If End If End If Set f = Nothing Set fso = Nothing
-
WSskipro
AskWoody LoungerOctober 31, 2011 at 4:44 pm #1304782Thanks jscher2000. It works except….
My file needs to be in C:windows and the script des not work here. I have all permissions to allow and have run as admin with shortcut.
First part runs stating file and asking to change. If I choose yes, the file des not cahnge but if I try it again I get this error msg. See attached. -
WSjscher2000
AskWoody LoungerOctober 31, 2011 at 6:58 pm #1304798My file needs to be in C:windows and the script des not work here. I have all permissions to allow and have run as admin with shortcut.
First part runs stating file and asking to change. If I choose yes, the file des not cahnge but if I try it again I get this error msg. See attached.It didn’t occur to me to check whether the file exists already. Are you saying it doesn’t actually exist when you get this message??
If the issue is special permissions relating to the Windows folder, we could slide this discussion over to the relevant operating system board. Or you could post there with a link back to this thread to see whether there is a solution for that folder.
-
WSskipro
AskWoody LoungerNovember 1, 2011 at 4:56 pm #1304902It appears to be A UAC issue. I need it to allow the UAC to request permission and me to grant it for the file to make the changes. Can a “wait” be included between the first screen & chice and the actual file rename to give Windows time to get permission?
Interesting, simple batch files allow the UAC request and response to occur.What would I need to add to check if neither file exists, then give choice which to add.
How do I cross thread to Win 7 forum? I posted there and was informed that was improper.
-
-
RetiredGeek
AskWoody_MVPSeptember 27, 2012 at 12:12 pm #1350557Thanks jscher2000. It works except….
My file needs to be in C:windows and the script des not work here. I have all permissions to allow and have run as admin with shortcut.
First part runs stating file and asking to change. If I choose yes, the file des not cahnge but if I try it again I get this error msg. See attached.You can solve this problem by setting up a Scheduled Task {run on demand} with Admin Privileges then create a shortcut to the Task.
[noparse]C:WindowsSystem32schtasks.exe /run /TN “Your Shortcut Name Here”[/noparse] :cheers:
-
-
-
WSjscher2000
AskWoody Lounger -
WSskipro
AskWoody Lounger -
joep517
AskWoody MVPNovember 2, 2011 at 11:12 am #1305050The Script Center at Technet has a ton of information and links to resources.
Joe
--Joe
-
Paul T
AskWoody MVP
Viewing 5 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
What is wrong with simple approach?
by
WSSpoke36
35 minutes ago -
Microsoft-Backed Builder.ai Set for Bankruptcy After Cash Seized
by
Alex5723
7 hours, 4 minutes ago -
Location, location, location
by
Susan Bradley
7 hours, 32 minutes ago -
Cannot get a task to run a restore point
by
CWBillow
8 hours, 29 minutes ago -
Frustrating search behavior with Outlook
by
MrJimPhelps
3 hours, 27 minutes ago -
June 2025 Office non-Security Updates
by
PKCano
19 hours, 15 minutes ago -
Secure Boot Update Fails after KB5058405 Installed
by
SteveIT
1 hour, 19 minutes ago -
Firefox Red Panda Fun Stuff
by
Lars220
19 hours, 11 minutes ago -
How start headers and page numbers on page 3?
by
Davidhs
1 day, 5 hours ago -
Attack on LexisNexis Risk Solutions exposes data on 300k +
by
Nibbled To Death By Ducks
8 hours, 17 minutes ago -
Windows 11 Insider Preview build 26200.5622 released to DEV
by
joep517
1 day, 14 hours ago -
Windows 11 Insider Preview build 26120.4230 (24H2) released to BETA
by
joep517
1 day, 14 hours ago -
MS Excel 2019 Now Prompts to Back Up With OneDrive
by
lmacri
1 day, 3 hours ago -
Firefox 139
by
Charlie
20 hours, 34 minutes ago -
Who knows what?
by
Will Fastie
10 hours, 55 minutes ago -
My top ten underappreciated features in Office
by
Peter Deegan
1 day, 15 hours ago -
WAU Manager — It’s your computer, you are in charge!
by
Deanna McElveen
1 day, 9 hours ago -
Misbehaving devices
by
Susan Bradley
10 hours, 44 minutes ago -
.NET 8.0 Desktop Runtime (v8.0.16) – Windows x86 Installer
by
WSmeyerbos
2 days, 20 hours ago -
Neowin poll : What do you plan to do on Windows 10 EOS
by
Alex5723
18 hours, 18 minutes ago -
May 31, 2025—KB5062170 (OS Builds 22621.5415 and 22631.5415 Out-of-band
by
Alex5723
2 days, 19 hours ago -
Discover the Best AI Tools for Everything
by
Alex5723
1 day, 18 hours ago -
Edge Seems To Be Gaining Weight
by
bbearren
2 days, 9 hours ago -
Rufus is available from the MSFT Store
by
PL1
2 days, 17 hours ago -
Microsoft : Ending USB-C® Port Confusion
by
Alex5723
3 days, 20 hours ago -
KB5061768 update for Intel vPro processor
by
drmark
1 day, 20 hours ago -
Outlook 365 classic has exhausted all shared resources
by
drmark
1 day, 19 hours ago -
My Simple Word 2010 Macro Is Not Working
by
mbennett555
3 days, 16 hours ago -
Office gets current release
by
Susan Bradley
3 days, 19 hours ago -
FBI: Still Using One of These Old Routers? It’s Vulnerable to Hackers
by
Alex5723
5 days, 9 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.