LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Rename file sequential order

Hi,

I have some files into a folder, files name are:

1

3

5

6

9

...

 

I need to programmatically rename files in a numerical sequence (ascending order):

1

2

3

4

5

...

 

Could you please show me some good examples to do it?

 

Thanks 

 

0 Kudos
Message 1 of 10
(439 Views)

You can use the "Move" function. If you go in the order you've shown, there should not be any chance of overwriting. But, make sure you backup the files before you start playing with this function. 
https://www.ni.com/docs/en-US/bundle/labview-api-ref/page/functions/move.html?srsltid=AfmBOooCONpnGB...

0 Kudos
Message 2 of 10
(414 Views)

Dear Gregory, 

Thanks but I have no idea how move function can help. Could you please attach a .vi example?

 

0 Kudos
Message 3 of 10
(407 Views)

It's best if you try it first and then I can offer correction. You would use the original name as the "source path" and the new name as the "target path"

0 Kudos
Message 4 of 10
(400 Views)

maxnoder1995_0-1725994067364.png

 

0 Kudos
Message 5 of 10
(390 Views)

Hi,

I've tried it but it has problems with duplicated names. Anyway thanks for sharing it.

I've solved now with something like this.  Files extensions are not included at the moment.

0 Kudos
Message 6 of 10
(345 Views)

Hi Mal,

 


@Mal123 wrote:

I've tried it but it has problems with duplicated names. Anyway thanks for sharing it.

I've solved now with something like this.  Files extensions are not included at the moment.


  • Why do you list the folder content in each iteration of the loop?
  • Why don't you use the original listing from before the loop?

@Mal123 wrote:

I have some files into a folder, files name are: 1 3 5 6 9 ...

I need to programmatically rename files in a numerical sequence (ascending order): 1 2 3 4 5 ...


  • What is the relation between "before" and "after" names?
    Is it like "1->1, 3->2, 5->3, 6->4, 9->5" or is it like "1->2, 3->3, 5->5, 6->2, 9->4"???
  • What should happen when differences between numerical and alphabetical ordering occur?
    Like numerical ordering "1, 2, 3, 11, 20" vs alphabetical ordering "1, 11, 2, 20, 3"…
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(341 Views)

Hi,

With the external list we obtain the number of files. Then the name of files during each iterations could change for this reason the internal list.

 

About corrispondence of numbers for my needs is not matter.

The last question is interesting... indeed I didn't try with more files >10!

0 Kudos
Message 8 of 10
(332 Views)

Hi Mal,

 


@Mal123 wrote:

About corrispondence of numbers for my needs is not matter.


So your algorithm is "not well defined": either define the algorithm completely - or implement some error handling to handle your FileMove errors!

 


@Mal123 wrote:

The last question is interesting... indeed I didn't try with more files >10!


So your algorithm is "not well defined": define the algorithm completely!

 

When defining an algorithm you need to consider such things - and it seems you missed this part at all…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(327 Views)

Hi,

Replacing sort array with this useful string sort:

 

https://forums.ni.com/t5/Example-Code/Sort-String-Array-Using-Common-Alphabetical-and-Numeric-Logic/...

 

It works fine for my case: no matter file sequence, important names are in a numerical sequence. 

 

0 Kudos
Message 10 of 10
(319 Views)