cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 

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
Mensaje 1 de 10
1.054 Vistas

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
Mensaje 2 de 10
1.029 Vistas

Dear Gregory, 

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

 

0 kudos
Mensaje 3 de 10
1.022 Vistas

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
Mensaje 4 de 10
1.015 Vistas

maxnoder1995_0-1725994067364.png

 

0 kudos
Mensaje 5 de 10
1.005 Vistas

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
Mensaje 6 de 10
960 Vistas

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
Mensaje 7 de 10
956 Vistas

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
Mensaje 8 de 10
947 Vistas

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
Mensaje 9 de 10
942 Vistas

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
Mensaje 10 de 10
934 Vistas