Page 1 of 1

Recursive alpha sort the contents of selected files/folde

Posted: 30 Sep 2016 18:16
by lukescammell
I have a kind of general text manipulation question, but I know how good some of your xy scripting gurus are, so I figured it was worth asking here. Of course, if there’s a better tool for the job, I’d be equally happy to be pointed in the right direction.

I would like to alpha sort the lines (contents) of all the files in a folder, or selection of files and folders, recursively.

Is xyscripting a sensible way to approach this? If so, would anyone be kind enough to write this? This is for a mobile game wiki that I edit and not for any kind of business application (though I’m sure someone would find it useful for that).

Thanks!

Edit: after the file contents have been alphabetised, I then feed them through BeyondCompare to find out what has changed between versions of the game so I can update the wiki…

Re: Recursive alpha sort the contents of selected files/fold

Posted: 30 Sep 2016 19:10
by highend
Foreach loop over all selected files
Readfile to get the content
Formatlist the content recursively
Writefile the new content back

On vacation no time to write real code...

Re: Recursive alpha sort the contents of selected files/fold

Posted: 03 Oct 2016 14:10
by TheQwerty
FYI, Beyond Compare can perform the sorting for you.

First ensure you have a "Sorted" format defined under Tools > File Formats... (included by default in BC 4):
2016-10-03 075541.png
2016-10-03 075541.png (60.77 KiB) Viewed 1995 times
Then when you're comparing files there's a drop-down that you can use to select "Sorted" comparison (EDIT: You must do this in each pane.):
2016-10-03 080057.png
2016-10-03 080057.png (40.37 KiB) Viewed 1995 times
If you wanted to have BC automatically apply the sorting you could configure the Sorted format's General > Mask field to match your files.

-----------------
Also, while XY scripting can be used to sort the files, Windows ships with a sort program which might be a better choice.


Hope that helps!

Re: Recursive alpha sort the contents of selected files/fold

Posted: 13 Oct 2016 12:26
by lukescammell
I do have a licence for BC4, so I will probably use that. Interesting about Sort! Thanks for everyone's help, I knew this would be the place to get answers ;)