Changing file extension
Changing file extension
Changing file extension
Changing file extension
Changing file extension
Changing file extension Changing file extension Changing file extension Changing file extension Changing file extension Changing file extension Changing file extension Changing file extension
Changing file extension Changing file extension
Changing file extension
Go Back  Xtreme Visual Basic Talk > > > Changing file extension


Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2004, 10:45 AM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default Changing file extension


I wrote a program as a utility for a game modification. The music format in the game is mp3 with a .mus extension instead of .mp3. I have it so it reads all of the bytes of the file and writes them to a filestream with the original file name that was stored in a string, minus the last 4 characters ie. the extension, and saves it with that string of characters & ".mus" in the music directory of the game. Is there a IO class for file extensions so I could simply copy the file to the directory and rename the extension?
Reply With Quote
  #2  
Old 10-30-2004, 01:08 PM
MKoslof's Avatar
MKoslofChanging file extension MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

If you are implying is there an IO property that by default knows all valid extensions for files and will convert formats, then no, not that I know of. Any file type conversion is going to have to done by you or via a third party application that can understand and change the format of the existing file.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 10-30-2004, 01:34 PM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

There is no conversion going on. The input format is plain mp3, and the output is the same exact thing with ".mus" instead or the ".mp3" extension. As I said above, the game's music format is just mp3 with .mus extension.

Last edited by blindreaper666; 10-30-2004 at 01:39 PM.
Reply With Quote
  #4  
Old 10-30-2004, 01:36 PM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

This is the same as having two files: image1.jpg and image1.jpeg. Both could be identical, but have a different extesion if that clears it up at all.
Reply With Quote
  #5  
Old 10-31-2004, 08:18 AM
MKoslof's Avatar
MKoslofChanging file extension MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Right, so what type of class are you looking for? Either way, there is no native .Net method to do what you are trying to accomplish.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #6  
Old 10-31-2004, 07:06 PM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

So, would it just be easier to trim the string of the file name at the period character and combine that with another string containing my extension?
Reply With Quote
  #7  
Old 11-01-2004, 11:40 AM
Ralphzehunter Ralphzehunter is offline
Freshman
 
Join Date: Oct 2004
Posts: 27
Talking My way to do it

Here is how you could do it tho
First, dim a string that will hold the filename. Then dim an integer.
Next, set the string to whatever filename you would like to change the extension to. Then make a for loop, looping through 1 to string.length - 1.
In the for loop, check to see if string.chars(x or whatever your for variable is) if it is equal to ".", and if it is, then set mynumber to x, and exit the for loop. Then have the string = mid(thestring,1,thenumber+1) & "mp3". Then you can save it with the name of your string. That's all folks!

Here is the source how to do it.

Code:
        Dim thename As String
        Dim thenumber As Integer
        thename = "Your file.ext"
        For x As Integer = 1 To thename.Length - 1
            If thename.Chars(x) = "." Then thenumber = x
        Next
        thename = Mid(thename, 1, thenumber + 1) & "mp3"
Mid is a command that gives you a part of a string in the form of mid(your string, where to start, how long do you want the part to be), or mid(your string, where to start), which gives you the whole string starting at the start point.

That's what you wanted to do, right?
__________________
Heh... I'm invisible.

Last edited by Ralphzehunter; 11-01-2004 at 11:53 AM. Reason: I want to explain the commands I used
Reply With Quote
  #8  
Old 11-02-2004, 03:20 PM
Ralphzehunter Ralphzehunter is offline
Freshman
 
Join Date: Oct 2004
Posts: 27
Default I feel stupid

...... Man, I feel really stupid. I made up my own splitter procedure when I could have told you to use the split command.
You could use the split command, and use the first substring of and your extension to save it.
__________________
Heh... I'm invisible.
Reply With Quote
  #9  
Old 11-08-2004, 12:19 AM
dric dric is offline
Newcomer
 
Join Date: Nov 2004
Posts: 1
Default but how do you acutally rename the file?

I have an almost identical problem, where I want to simply change the extension of a file. I understand the bit about getting the filename which is coded above, i've done that. I'm just stuck trying to figure out how to rename it.
eg: file.filename = string???... like HOW do you rename it?
Reply With Quote
  #10  
Old 11-08-2004, 08:01 AM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

I just trim the string at a substring starting at the period now.
Reply With Quote
  #11  
Old 11-08-2004, 08:04 AM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

I am going to make custom class that has a name and extension property that reads all the bytes of a file into an array or string that I can access so it will be like an ideal file for me to use.
Reply With Quote
  #12  
Old 11-08-2004, 10:21 AM
JustAdotNETUser JustAdotNETUser is offline
Freshman
 
Join Date: Oct 2004
Posts: 42
Default

I may have this wrong but it seems the original question was just asking to change a 'mus' extension to an 'mp3' extension..... or am I wrong?

Anyway, there's a real easy way using the '.split(".")' method, but, as with the above examples you may run into problems if your file for example is called: 'my.sound.file.mus', anyway, if it's just an extension change you want then this is what I'd use, short and sweet:

Code:
File.Move(Source, Source.Substring(0, Source.Length - 3) & "mp3")
Source being a String varible containing the FULL path to the file and you need to 'imports System.IO' for the 'File.Move'

Obviously you'll need a loop routine to go through your files blaa blaa blaa

Last edited by JustAdotNETUser; 11-08-2004 at 10:26 AM.
Reply With Quote
  #13  
Old 11-08-2004, 10:33 AM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

How about reversing the string then finding the first period? If you have an extension like .html then that code won't work. Just a thought though...
__________________
170 10101010 410 J31^170
Reply With Quote
  #14  
Old 11-08-2004, 11:32 AM
JustAdotNETUser JustAdotNETUser is offline
Freshman
 
Join Date: Oct 2004
Posts: 42
Default

lol, and didn't I just know someone was gonna say that.

Because the files and originally question is NOT .html, they're .mus (original post). The question to this thread was to change mus to mp3.
Reply With Quote
  #15  
Old 11-08-2004, 02:38 PM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

It is just the extension I am changing. I am writing a custom class that has a string for name and one for extension that the user enters and it combines them with a period between. It opens a file and gets the bytes so it can take any file and rename it the way I wanted to originally do it, but I didn't think of that when I originally wrote this thread so I have answered my own question, but thaks for all the suggestions.
Reply With Quote
  #16  
Old 11-08-2004, 04:05 PM
by_m's Avatar
by_m by_m is offline
Contributor
 
Join Date: Jul 2004
Location: Texas
Posts: 661
Default

Quote:
Originally Posted by JustAdotNETUser
lol, and didn't I just know someone was gonna say that.

Because the files and originally question is NOT .html, they're .mus (original post). The question to this thread was to change mus to mp3.
I thought about that too but since blindreaper was talking about a class I figured he might want to make it useful for more than one application. That's why I posted.
__________________
170 10101010 410 J31^170
Reply With Quote
  #17  
Old 11-08-2004, 04:28 PM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

Well, it will work with more than one application as with any class. If anyone wants it when I am done, I will post it here. I call it FilePlus, because that's essentially what it is, it can do most common filesystem tasks plus more and special features for certain file types like mp3/wma tag editing when I get it workng properly.
Reply With Quote
  #18  
Old 11-09-2004, 06:58 AM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

Quote:
Originally Posted by JustAdotNETUser
lol, and didn't I just know someone was gonna say that.

Because the files and originally question is NOT .html, they're .mus (original post). The question to this thread was to change mus to mp3.
Also, that would work for what I am trying to do. I just need the extension changed so finding the first period in reverse order would be a good way to do it.
Reply With Quote
  #19  
Old 11-18-2004, 02:27 PM
blindreaper666's Avatar
blindreaper666 blindreaper666 is offline
Junior Contributor
 
Join Date: Aug 2004
Posts: 317
Default

Just wanted to post that on MSDN i found that there is a way to change a file extension in .net. Check it out here:
http://msdn.microsoft.com/library/de...nsiontopic.asp
Reply With Quote
  #20  
Old 11-18-2004, 05:36 PM
MKoslof's Avatar
MKoslofChanging file extension MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Hmm...nice, didn't know about that procedure. Thanks for the info . Good luck.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Changing file extension
Changing file extension
Changing file extension Changing file extension
Changing file extension
Changing file extension
Changing file extension Changing file extension Changing file extension Changing file extension Changing file extension Changing file extension Changing file extension
Changing file extension
Changing file extension
 
Changing file extension
Changing file extension
 
-->