renaming / reordering app source files

114 views
Skip to first unread message

Tom Farrell

unread,
Jul 10, 2022, 2:32:59 PM7/10/22
to DroidScript
As mentioned my subject field, I want to be able to rename and reorder my app's source code files.  I don't see a direct way to do this.  Only way I can figure it at present is to create new files with the names and in the order I want, copy the contents of the old files into the new files, and then delete the old files.  One glitch to this scheme is that you cannot delete the first file.

One could say I should have thought all this through in advance, but programming DroidScript is a bit more freeform that software development which I have done professionally, so that splitting off my app into multiple .js files seems to occur organically as I evolve my app.

Any help with this would be appreciated.  Thanks!

Alan Hendry

unread,
Jul 10, 2022, 3:23:24 PM7/10/22
to DroidScript
HI,
The android Files app should be able to rename your files (then use DS to modify the app.Script statements).
(Android 10+ has scoped storage so I use Xplore a free app from the Google Play Store)
As far as I can see you should be able to write your own app to list the folders in DS,
choose one, list the files in the folder, choose one, type a new name, rename .
When running your app under DS you should have access to all DS projects/apps.
Regards, ah

Right2TheV0id

unread,
Jul 11, 2022, 3:08:38 PM7/11/22
to DroidScript
I created a tool to help me rename files "from within DroidScript".
This is not perfect but it could help you to perform what you're looking for.
This is a work in progress and it could be greatly improved.

To use it simply install the SPK on your phone.
Then, in the project you're trying you rename your files, import the lib with the following code:

app.LoadScript( "../RenameSourceFile/RenameSourceFile.js" );
// You can execute the spk to copy this code in your clipboard automatically

Once it's loaded, you can use it like this:

RenameSourceFile();  // Prompt for source and destination file.
RenameSourceFile( "script.js" );  // Prompt for destination file only.
RenameSourceFile( null, "renamed.js" );  // Prompt for source file only.
RenameSourceFile( "script.js", "renamed.js" );  // Only prompt the confirmation dialog.
RenameSourceFile( "script.js", "renamed.js", true );  // Rename without any prompting.

Notes:
 
- can move files between folders if folders already exists.
- changes takes effect immediatly, but the IDE needs to be refreshed:
    - Wifi IDE: actualise the page (F5).
    - Mobile IDE: exit the current project then reopen it.
- Mobile IDE: Accessing the source file again before refreshing the IDE will create an empty file (DS behavior).
    - Thus it is preverable to be on the main app file when before calling RenameSourceFile.
RenameSourceFile.spk

Dave

unread,
Jul 12, 2022, 4:52:43 AM7/12/22
to DroidScript
If you are using the wifi IDE (and you are premium), then you can simply use the built-in file browser to rename your project files.

Also, if you have previously bee a professional coder, then I would expect you to be most comfortable using the wifi IDE in premium mode rather than trying to edit on your device directly.

Alan Hendry

unread,
Jul 15, 2022, 12:02:55 PM7/15/22
to DroidScript
HI,
I modified a little app so that it can rename any file within DS. No validations.
Due to Android file security, probably won't work as an APK/AAB.
Did a little testing (on ChromeBook). Touch a folder, then touch a file, type in the new name, touch the button.
Regards, ah

function OnStart() {
    gp = app.GetPath()
    lay = app.CreateLayout("Linear","horizontal,top")
    folders = app.AddList(lay,app.ListFolder(gp),0.5)
    folders.SetOnTouch(Files)
    files = app.AddList(lay,"")
    app.AddLayout(lay)
   
    dlg = app.CreateDialog("Rename")
    dlglay = app.CreateLayout("linear")
    dlg.AddLayout(dlglay)
    te = app.AddTextEdit(dlglay,"")
    but = app.AddButton(dlglay,"Rename")
    but.SetOnTouch(function () {
        from = gp+"/"+foldername+"/"+filename
        newfile = te.GetText()
        to = gp+"/"+foldername+"/"+newfile
//alert(from) ; alert(to)
        app.RenameFile(from,to)
        files.SetItemByIndex(globalindex,newfile)
        dlg.Hide()
    }) // ontouchup
}// fn
function Files(title,body,icon,index) {
    foldername = title
    files.SetList(app.ListFolder(gp+"/"+title))
    files.SetOnTouch(Rename)
} // fn
function Rename(title,body,icon,index) {
    filename = title
    globalindex = index
    dlg.SetTitle(title)
    te.SetText(title)
    dlg.Show()
} // fn

Tom Farrell

unread,
Jul 15, 2022, 12:09:36 PM7/15/22
to DroidScript
Thanks, I will take a look!
Reply all
Reply to author
Forward
0 new messages