From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning new names to List of files

Solved!
Go to solution

Hello Everyone, 

I just have a small problem. I have this VI that I developed (Attached) which can load CSV files from a directory and then plot them in XY graph. My small problem is, is there any way I can take this list of files and then assign new names to them with random numbers and letters? I want to do this in the same VI or maybe in separate VI through Labview. Because I got over thousands of files that I need to rename without necessarily changing the content of them. I have attached files if someone wants to test out the Vi

Download All
0 Kudos
Message 1 of 23
(3,886 Views)

It's definitely possible, but why would you rather give a file a random name instead of a unique, descriptive name?

0 Kudos
Message 2 of 23
(3,870 Views)

This is actually for the company that I am working. Yes, I know it sounds a bit weird. Out file names are unique and descriptive already. these are all test data files. I have only attached a small list of files. But some of them has huge descriptive name. That later becomes a problem. So one part is that we are building a database to keep track of the file parameters but also we want to change the file names and keep it small. With these two we don't have to deal with big file names. 

0 Kudos
Message 3 of 23
(3,866 Views)

I see, you will still probably want something sequential, either a number or a date/timestamp to make sure you don't repeat filenames. Just like in databases where it can auto-increment the primary key for. 

 

If each test gives you N files, you can have names like:

00003847_file0 ... 00003847_fileN

Then next test you would have 

00003848_file0 ... 00003848_fileN

Message 4 of 23
(3,851 Views)

If you really want random names (we encounter a need for this all the time), here's one way to do this:

In a For loop with N=6 (for a 6-letter Random Name), use the Random Number Generator to give you a U8 from 0 to 61.  Use a Case Statement for three Cases -- 0..9 (which will be the number 0 to 9), 10..35 (a..z), and everything else (A..Z).  Let's do the middle case (the others are similar).  First, subtract 10, giving you 0..25.  Use "String to Byte Array" to change "a" to a Byte Array representation of the letter, and use Index Array to get the first element, which you add to your Random Number - 10 -- this gives you the byte representation of a random letter from a..z.  Do the same for the other two cases, subtracting nothing from 0..9 and adding the byte representation of "0", and subtracting 36 from Default (36..255) and adding "A".  Assemble the Array using an Indexing Tunnel from the For loop, do Byte Array to String, and there's your Random Name.

 

I assume you can do the rest using ordinary File I/O Functions.

 

Bob Schor

Message 5 of 23
(3,843 Views)

I meant to note that 6 random uppercase+lowercase+numerals gives over 50 billion unique names.  You could test for repetitions, but it is sufficiently unlikely as to be ignored (or add two more characters to get more than 200 trillion names).

 

Bob Schor

Message 6 of 23
(3,839 Views)

Not completely sure what you are looking for here.  Names can be simple and/or organized into folders.  Here is something that I threw together based on some of your data.  Assuming that you have hundreds of filenames, then a well sorted directory might be best with simple names.  I did place a few of your files into the wrong directories to display my thoughts here.

Shortnames.png

The Menu selection options here would be the same as you had shown on your window.  If desired, you could craft this a little further and have them choose each option separately and leave an option that if unselected, it would show all available for that particular option.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
Message 7 of 23
(3,839 Views)

Gregoryj, 

Sorry for the late reply. I think what you suggested is a better idea. I just need to know how to do that. I'll check other the other replies to see if I can get something. 

0 Kudos
Message 8 of 23
(3,794 Views)

Hello Minions, 

Thank you very much for the VI block diagram. I wanted to check it but It turned out to be a snapshot, not an actual VI snippet. However, I can still replicate your block diagram in Labview by making it but if you can attach the actual snippet, that would be great! Thank you again. 

0 Kudos
Message 9 of 23
(3,787 Views)

The snippet seemed to work for me, but I instead uploaded the vi this time.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
Message 10 of 23
(3,780 Views)