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.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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, 7 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
-
Sometimes I wonder about these bots
by
Susan Bradley
2 hours, 34 minutes ago -
Does windows update component store “self heal”?
by
Mike Cross
8 hours, 39 minutes ago -
Windows 11 Insider Preview build 27858 released to Canary
by
joep517
9 hours, 39 minutes ago -
Pwn2Own Berlin 2025: Day One Results
by
Alex5723
9 hours, 4 minutes ago -
Windows 10 might repeatedly display the BitLocker recovery screen at startup
by
Susan Bradley
5 hours, 34 minutes ago -
Windows 11 Insider Preview Build 22631.5409 (23H2) released to Release Preview
by
joep517
12 hours, 21 minutes ago -
Windows 10 Build 19045.5912 (22H2) to Release Preview Channel
by
joep517
12 hours, 22 minutes ago -
Kevin Beaumont on Microsoft Recall
by
Susan Bradley
56 minutes ago -
The Surface Laptop Studio 2 is no longer being manufactured
by
Alex5723
20 hours, 30 minutes ago -
0Patch, where to begin
by
cassel23
14 hours, 32 minutes ago -
CFPB Quietly Kills Rule to Shield Americans From Data Brokers
by
Alex5723
1 day, 10 hours ago -
89 million Steam account details just got leaked,
by
Alex5723
21 hours, 53 minutes ago -
KB5058405: Linux – Windows dual boot SBAT bug, resolved with May 2025 update
by
Alex5723
1 day, 18 hours ago -
A Validation (were one needed) of Prudent Patching
by
Nibbled To Death By Ducks
1 day, 9 hours ago -
Master Patch Listing for May 13, 2025
by
Susan Bradley
20 hours, 47 minutes ago -
Installer program can’t read my registry
by
Peobody
3 hours, 27 minutes ago -
How to keep Outlook (new) in off position for Windows 11
by
EspressoWillie
1 day, 7 hours ago -
Intel : CVE-2024-45332, CVE-2024-43420, CVE-2025-20623
by
Alex5723
1 day, 14 hours ago -
False error message from eMClient
by
WSSebastian42
2 days, 5 hours ago -
Awoke to a rebooted Mac (crashed?)
by
rebop2020
2 days, 14 hours ago -
Office 2021 Perpetual for Mac
by
rebop2020
2 days, 16 hours ago -
AutoSave is for Microsoft, not for you
by
Will Fastie
2 hours, 43 minutes ago -
Difface : Reconstruction of 3D Human Facial Images from DNA Sequence
by
Alex5723
2 days, 19 hours ago -
Seven things we learned from WhatsApp vs. NSO Group spyware lawsuit
by
Alex5723
3 hours, 2 minutes ago -
Outdated Laptop
by
jdamkeene
3 days, 1 hour ago -
Updating Keepass2Android
by
CBFPD-Chief115
3 days, 6 hours ago -
Another big Microsoft layoff
by
Charlie
3 days, 6 hours ago -
PowerShell to detect NPU – Testers Needed
by
RetiredGeek
8 hours, 16 minutes ago -
May 2025 updates are out
by
Susan Bradley
9 hours, 58 minutes ago -
Windows 11 Insider Preview build 26200.5600 released to DEV
by
joep517
3 days, 12 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.