Operation on external files

Let’s say I have 100 jpg files named 001 to 100. I want to save them in reverse order.
How do I do it. Spent last hour trying to crack it and failed.

Do you mean renaming them so that 100 becomes 001 etc?

// Rolf


You might have to rename them to a temporary name (adding to the names), and after that, remove the temporary names.

For example the following files


could be renamed to


And finally remove the original “trailing” number (the “-001” … “-100” part). In this way there won’t be any name clashes.

Perhaps there are smarter ways but this came off the top of my head.

// Rolf

How would you automate it? Still can’t imagine it.
I was trying to do like this but it’s not working (guess it’s totally dumb)

A Python or C# script would do.

// Rolf

Sure it would, but it’s beyond my skills :frowning:

OK, I see that there’s a Lunchbox component which can save the files. But is there any component that actually loads the files (the content) so it can be stored under a different name? if so, you can simply manipulate the file names (as text strings) and store the files as I suggested

(I haven’t tried this myself using only GH components so I don’t know if its possible to load & save as described)

// Rolf

I know someone has been doing similar stuff but it was long time ago and I can’t find the thread.

Does it have to be in grasshopper or you can use any tool? On a Mac :stuck_out_tongue_winking_eye: you could use Automator to do that. Link

I’d rather find universal solution that works everywhere.

Didn’t you say that you have a Mac? Does why I posted this solution, I was just trying to help.

I have Mac with Windows installed and I have PCs too. It is more of a knowledge challenge for me rather than real need, otherwise i’d google for platform solution.

That’s ok then.


Well, you might start “reverse-engineering” small snippets like this one and find yourself programming in c# in no time! … like i did time ago…

I’ve used System.IO, which is a MS library that lets you interact with files and folders. It is added to the c# script with a “using statement” at the top of the script…

2020-05-07 21_49_16-Grasshopper - invert_names_order
invert_names_order.gh (3.8 KB)

To me, this is working.

It actually rename the files twice, as the first would temporary have the same name of the last, or vice-versa.
If your starting names are a plain number “1” or “20” without extension, this script need to be edited.
Also, this rename ALL the files of a given folder… i’m not expert but you better test/use it with a dedicated subfolder containing only the files to rename… :sweat_smile:
(…and make a backup of those files before trying… who knows?!)


  private void RunScript(string folder_path, bool Do_it)
      string[] file_names = Directory.GetFiles(folder_path);
      int count = file_names.Length;
      List<string> old_names = new List<string>(file_names);
      for(int i = 0;i < count;i++){
        System.IO.File.Move(file_names[i], folder_path + i);
      for(int i = 0;i < count;i++){
        int ii = count - (i + 1);
        System.IO.File.Move(folder_path + i, old_names[ii]);

Thanks for your input, really appreciate it.
All I do is concept work with some fine engineering.
There is so much to learn and coding is still on my list. I’ve installed Blender to extend my skillset but have no time to sit and dig into it. I’d love to be better in Grasshopper, Photoshop, illustrator but the day has only X hours and I already need to be dragged to bed.

Get rid of your bed. :crazy_face:

But I do understand, it does take some time to get programming into your head. Life is about priorities.

// Rolf

I don’t sleep alone, it’s worthing going there sometimes :laughing:

FWIW the day has XXIV hours…

A day - bed time = hours available
that’s my math and it can be something between 24 and 12 :slight_smile: