File Extensions for Projects

I hope you will find the following code useful, BUT it has not really been tested (other than bits and pieces). I would greatly appreciate it if someone would check it out to see if it has any bugs.

Here’s what it does: After you tell it what directory to work with, it takes all files with the older Real Studio file extensions (".rbp" and “.xml”) and replaces those extensions with the newer Xojo extensions (".xojo_binary_project" and “.xojo_xml_project”).

Here’s the code:

Dim dlg As SelectFolderDialog Dim f As FolderItem Dim I As Integer, Pos1 Dim FilenameWithoutExtension As String Dim OldExtension, OldFilename As String Dim NewExtension, NewFilename As String dlg = New SelectFolderDialog f = dlg.ShowModal If f <> Nil Then For I = 1 To f.Count OldFilename = f.Item(i).Name Pos1 = InStr (OldFilename, "." ) If Pos1 <> 0 Then FilenameWithoutExtension = Left ( OldFilename, Pos1 - 1) OldExtension = Mid (OldFilename, Pos1) If OldExtension = ".xojo_binary_project" Then NewExtension = ".rbp" Elseif OldExtension = ".xojo_xml_project" Then NewExtension = ".xml" End If If NewExtension = ".rbp" Or NewExtension = ".xml" Then NewFilename = FIlenameWithoutExtension + NewExtension f.Item(i).Name = NewFilename If f.LastErrorCode > 0 then MsgBox Str("Error: " + Str ( f.LastErrorCode) ) End if End If End If Next I End If

It you want the process to go in the other direction, just modify these lines accordingly:

If OldExtension = ".xojo_binary_project" Then NewExtension = ".rbp" Elseif OldExtension = ".xojo_xml_project" Then NewExtension = ".xml" End If

Enjoy (AFTER someone has checked it out)!

Barry Traver

A script applciation (either WindowsScript or AppleScript) will be better at this game (I think).

In fact, I use widely AppleScript for bits like that.

I don’t have a Mac (yet), so I can’t use Apple Script, BUT can you show us how to use “Windows Script” to change file extensions of Project files in a Folder?

I learn best from specific examples of code, so if a Script is “better at this game,” show me one that can do what my code tries to do and I’ll be much indebted to you (as other people here also probably will also). Thanks!

Barry Traver

You can’t be serious! Who on earth should want that? :frowning:

Thanks for putting in the work for this and sharing it freely with anyone who wishes to use it!

Andre,

I myself prefer “.rbp” and “.xml,” but you can go either way with little difference in my program.

Barry Traver

[quote=24989:@Barry Traver]Andre,

I myself prefer “.rbp” and “.xml,” but you can go either way with little difference in my program.

Barry Traver[/quote]

Sure, i realised that, but in the registry on windows you have to restore the RS-settings too after each new release otherwise your program is of little or no use for me.

Andre… I can see questioning the usefulness of a process… but do you need to be so rude in doing so?

And why would you need to change the registry? RS2012 knows what RBP and XML are… . XOJO knows what RBP, XML, xojo_binary_project, and xojo_xml_project are.

Andre,

I’m not sure what you’re saying (perhaps partly because I ordinarily stay away as much as possible from anything involving the Windows registry).

When I begin with the Start button on Windows 7, I can access at least two versions of Real Studio and at least two versions of Xojo. (I’m not as successful with the Windows desktop.) A shorter file extension makes working with my Real Studio and Xojo progrms much easier for me and perhaps some other people. (If not, at least I tried.)

I have dozens of folders with Real Studio or Xojo programs in them. Because of my Parkinson’s Disease, working with the keyboard is not the easiest thing in the world for me, so I cut down on typing wherever I can.

If my program is “of little or no use” to you," that’s all right. (It’s not a great program.) Like most of my programs, it does have one advantage: it’s free! I just hope that some people may find it useful.

Barry Traver

Dave, i don’t see where i was rude, if i was then i apologize because it was not meant to be.

For me this whole change of the file extensions is one of the many design misstakes in the Xojo IDE and just as unneccessary as the rebranding.

Changing the registry is needed because every time i want to save in another format Xojo will add its own extensions. Besides that, i use regularly registrycleaners and everytime i would have to check the lists of unused extensions etc. before removing them. And please don’t think too easy about that, Xojo installed over 15 Kb of changes in the registry. Also there is no filemanager that works nicely with those silly extensions.

Andre,

No apology needed. “Where no offense is intended, none is taken.”

Barry Traver

Barry, i am glad you take this not as a personal attack and i am sorry to hear you suffer from Parkinson. My handicap is reading, it takes me about 5 times longer than an avarage person. For me those extensions make it very hard to see where the filename ends and where the extension starts.

Again, sorry, it wasn’t meant to be harsh to you, maybe my poor English is playing games with me.

I’ve run into a problem and I have a hypothesis as to what is causing it, but I need help in fixing it.

The problem is that only some of the files get their file extensions changed that should get changed. That is, although no files get changed that shouldn’t get changed, not all of the files that should get changed get changed.

My hypothesis (and it’s only a guess, so I may be entirely wrong) is that when a filename is changed, the list of files is changed (i.e., they are again alphabetized, and the file that should have been next is no longer next but has gotten moved so that a different file gets processed next).

By the way, I took two precautions when I was testing: (1) Even if a filename got changed that shouldn’t have gotten changed, I could easily manually change it back again, since only the file extension was being changed. (2) I made frequent use of the MsgBox (I know, using MsgBox in debugging is as highly regarded as GoTo in programming, but bad habits die hard).

Here’s the problem code:

Dim dlg As SelectFolderDialog Dim f As FolderItem Dim I, Pos1 As Integer Dim FilenameWithoutExtension As String Dim OldExtension, OldFilename As String Dim NewExtension, NewFilename As String Dim Err As Integer dlg = New SelectFolderDialog f = dlg.ShowModal If f <> Nil Then For I = 1 To f.Count OldFilename = f.Item(I).Name MsgBox "OldFilename " + OldFilename Pos1 = InStr (OldFilename, "." ) MsgBox "Pos1 " + Str ( Pos1 ) If Pos1 <> 0 Then FilenameWithoutExtension = Left ( OldFilename, Pos1 - 1) MsgBox "FilenameWithoutExtension " + FilenameWithoutExtension OldExtension = Mid (OldFilename, Pos1) MsgBox "Old Extension " + OldExtension NewExtension = "" If OldExtension = ".rb" Or OldExtension = ".rbp" Then NewExtension = ".xojo_binary_project" End If If OldExtension = ".xml" Then NewExtension = ".xojo_xml_project" End If MsgBox "New Extension " + NewExtension If NewExtension <> "" Then NewFilename = FIlenameWithoutExtension + NewExtension MsgBox "NewFilename " + NewFilename f.Item(i).Name = NewFilename MsgBox NewFilename + EndOfLine + "CHANGED!" Else MsgBox NewFilename + EndOfLine + "NOT CHANGED" End If End If Next I End If MsgBox "Finished"

Am I correct in my analysis (or guess) as to what is happening? If so, how do I fix it so that the alphabetical re-arrangement of files won’t cause a problem? (I have another guess: that this is not a simple problem to solve .)

Thanks in advance for any advice.

Barry Traver

P.S. There are also other possible hypotheses, e.g., the problem may be due to my inability to distinguish between a comma and a period .

just as a test… try this

change
For I = 1 To f.Count

to

FOR i=f.count downto 1

Just a note of caution–be sure you don’t have other .xml files that aren’t RB projects. XML is used in a lot of stuff.

Try collecting all the files first into an array and then process that array

[code]if f <> nil then

dim fa() As FolderItem
for i As integer = 1 to f.Count
fa.Append f.Item(i)
next

for i As integer = 0 to fa.Ubound
//process folderitem fa(i)
next

end[/code]

Sorry, but there is one more thing to make the situation a bit more complicated. Suppose that what my program does is update the file extensions (from “.xml” to “xojo_xml_project” and from “.rb” and “.rbp” to “xojo_rbp_project”) in a folder of the user’s choice. Now, suppose further that that folder already contains, say, the files “HanoiSolution.xojo_rbp_project” and “HanoiSolution.rbp”.

My program can’t change the filename from “HanoiSolution.rbp” to “HanoiSolution.xojo_rbp_project” because there already is a file in the folder named “HanoiSolution.xojo_rbp_project”. (Think about it. I didn’t.)

There are several ways that sort of situation can be handled, but I need to decide what to do and to write the code to do it. That situation can be handled, but it is one more complication in an already-complicated program…

Barry Traver

Hi Barry!

You might also check out my Transmogrify program I wrote about in RSD 10.9 (the RS project file can be downloaded here). It’s a very useful general purpose drag-and-drop converter program that uses RBScripts (now XojoScripts) to do the actual conversion.

The advantage of this are that 1) you only have one program that can do all sorts of conversions, and 2) you can add new capabilities (new conversion types) at any time, without recompiling, and 3) you can fix bugs or enhance existing conversions by editing scripts without having to recompile the main app.

One of the examples I demonstrate in the app is a filename changing program. It would be trivial to adapt that code to do what you’re doing (or just adapt your code above into a script). Then you can just choose the conversion script you want (convert xml to xojo format or vice versa) and drop a folder or bunch of files into the window and it converts them.

I use Transmogrify every day for all sorts of tasks (I have about 2 dozen scripts installed in it and I write new ones periodically as needed).

And if there are externals this will have just broken them since it hasn’t renamed the items in the actual manifest
Same for VCP projects

There’s really no need to change the names as Xojo will open either

doofus,

The following (based on your suggestion) seems to work: Thanks!

Dim dlg As SelectFolderDialog Dim f As FolderItem Dim I, Pos1 As Integer Dim FilenameWithoutExtension As String Dim OldExtension, OldFilename As String Dim NewExtension, NewFilename As String Dim Err As Integer dlg = New SelectFolderDialog f = dlg.ShowModal If f <> Nil Then DIm fa() As FolderItem For i = 1 to f.Count fa.Append f.Item(i) Next I For I = 0 To fa.UBound OldFilename = fa(I).Name Pos1 = InStr (OldFilename, "." ) If Pos1 <> 0 Then FilenameWithoutExtension = Left ( OldFilename, Pos1 - 1) OldExtension = Mid (OldFilename, Pos1) NewExtension = "" If OldExtension = ".rb" Or OldExtension = ".rbp" Then NewExtension = ".xojo_binary_project" End If If OldExtension = ".xml" Then NewExtension = ".xojo_xml_project" End If If NewExtension <> "" Then NewFilename = FIlenameWithoutExtension + NewExtension fa(i).Name = NewFilename End If End If Next I End If MsgBox "Finished"

Barry Traver