From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: 

Copy entire folder into another folder on USB drive

Every time my program runs it will save an excel .csv file with data onto a SD card located in my controller. I'd like to the user to be able to stick in their USB thumb drive and copy the data to it from the SD card. I am having trouble implementing this programmatically. I receive error code:7 which I think is file not found. For now I am just trying to get the basics of copying a file from my C drive to another folder on the C drive. Once I get that working I'll work on the specifics on my application. Attached is my VI.

0 Kudos
Message 1 of 7
(3,835 Views)

Hi MicahKurtz,

 

I was able to copy files between these paths on Windows 7 using LabVIEW 2016 with your code. Make sure you are using the correct outputs from the List Folder function. There are two separate string array outputs for files and directories. Depending on what you want to do, you may want to use one or both (concatenate the arrays in this case). I concatenated them for testing and it detected and copied everything in the Source directory.

 

You may have found it already, but here is a link for writing to an external USB from LabVIEW:

Writing to an External USB Drive or SD Card from a LabVIEW Real-Time Device

Your goal seems slightly different than what is described in the article, but this should give you a starting point and some intuition about pathing to USB drives.

 

If you are still having issues, make sure you are using the proper path format for your operating system. Let me know if you need any more assistance!

 

Duncan W.

0 Kudos
Message 2 of 7
(3,812 Views)

Thanks Duncan,

 

I was able to get this to copy files to different directories on the same SD card, but now I'm having trouble getting it to copy from the SD card to the USB drive. My paths are as follows: SD card - /u/Source   USB drive - /v/Destination, following the procedure in the article you posted. No error is thrown, just nothing gets copied to the USB drive. I have written to the USB drive before, so I know the format is ok.

0 Kudos
Message 3 of 7
(3,782 Views)

Actually never mind, just got it to copy to the USB drive. It only works when I concatenate the outputs of the list folder function. Not sure I understand why.

0 Kudos
Message 4 of 7
(3,781 Views)

A few more questions. My current VI will copy data from the SD card to the USB drive only if there is only file on the SD card. Any more and error 7 gets thrown. Also this does not iterate through the entire folder, it just copies the latest file. Any ideas on how to fix this?

0 Kudos
Message 5 of 7
(3,777 Views)

You don't need (in this specific case) to concatenate the files and folders, and if you want to copy all of the .csv files, you shouldn't concatenate at all. Instead, use auto-indexing on the File Name (array) output at the For Loop boundary.

csv.png

The reason you get errors with more than one file is that the output of your List Files function is something like this:

 

File       Folder

a.csv    "" (blank)

b.csv    "" (blank)

 

and so when you concatenate them, the arrays are made into one string. Check the Context Help (Ctrl-H) for more details. The output (and input to your for loop) then becomes 

"a.csvb.csv", which doesn't exist.

 


GCentral
0 Kudos
Message 6 of 7
(3,769 Views)

Ah it seems there was a bit of miscommunication. You don't want to literally concatenate the array contents into a single string. Instead, in order to copy both files and directories, you would need to append one of the arrays to the end of the other. One way of doing this is to use the Insert Into Array function without an index input. There are also a number of other ways to append an array to the end of the other.

 

For your application, it seems you don't need to copy directories. If this is the case, I would disregard the "folder names" output of the List Folder function, as recommended by cbutcher. I would also highly recommend auto-indexing(check this out) as it will make your life easier and will automatically adapt the number of iterations of the for loop to match the number of files you would like to copy, which could be variable.

 

Duncan W.

0 Kudos
Message 7 of 7
(3,745 Views)