LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Copy and replace a folder with all its contents in labview

Solved!
Go to solution
I would like to know if there is a way to copy a directory and replace another directory with the first one, including all its contents?
If you could give me an example, I would really appreciate it.
0 Kudos
Message 1 of 10
(8,716 Views)

I don't have any examples.  But if you look in the File I/O palette, particular the Advanced File Functions palette below that, you'll find everything you need.

0 Kudos
Message 2 of 10
(8,712 Views)
The function is called copy.
0 Kudos
Message 3 of 10
(8,688 Views)

I made a vi that tries to copy a directory and replace it, but it doesn't do a thing. what I am trying to do is copy the directory and replace another directory with the first one, everytime a new file arrives into the source folder. I will leave my vi as an attachment.

Can someone please help me?

Thanks in advance!

0 Kudos
Message 4 of 10
(8,665 Views)

Can you provide more detail into exactly what you are trying to do?

 

You have a VI that runs forever because of the false wire to the Stop if True conditional terminal.  I really doubt you want your VI in an endless loop.

 

Your source files and destination file paths need to be set before you run your VI since they are only read at the beginning.

 

In case 0, you use recursive file list, which is a good idea for grabbing a list of files in a folder.  You pass that list of files onto a For Loop.  In th For Loop, you have an odd construct of comparing the iteration terminal to the number 1.  If True, you pass out a true to stop the For Loop.  If False, you pass out a False constant.  (Why the case structure?  Just eliminate it and pass the boolean value to the stop terminal.  but now you have something that will only run one or two times.  Passing out the only file in the list, or the 2nd file in the list.  Is that what you want?

 

Then it goes to case 1 and copies the source file path to the destination file path.  Are they both folders?  It should be since you send a folder to the List Files Recursive.  That seems like it is doing what you are asking for.  Is it working?

 

Then it goes to case 2 and deletes that file you got form case 0.  What is the point of that?

 

Then it repeats all over again going back to case 0 and since you have a False wired to the overall while loop.

 

Is that what you want?  It seems odd to me to get a file, copy an entire folder, then delete a file.

 

 

 

 

 

0 Kudos
Message 5 of 10
(8,660 Views)

This will copy and replace the files directly in a folder.  You can use another FOR loop to handle the directories.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 10
(8,658 Views)

Sorry f I didn't provide enough information. I am going to be updating the files in 2 different folders. I want the destination folder to have every file that is updated in the source folder, I want to delete every file in the source folder, but I don't want to lose the folder structure. That is why I want to copy and replace the entire folder and delete the file in the source folder. And I do want this to run forever, always checking if a new file exists.

Please help me out.

0 Kudos
Message 7 of 10
(8,652 Views)

Then why don't you use the Move File command?

 

What is putting files in the the first directory?  How frequently is it doing it?  Is there a risk that you start trying to move out a file from the first directory while it is still being written into that directory?  Do you want to instantly start checking that directory for new files and have it keep checking for new files as quick as the PC will allow?

 

 

0 Kudos
Message 8 of 10
(8,648 Views)
how would you keep the files in the same directory they are in the source folder. By the way I added a delay in the last case.
0 Kudos
Message 9 of 10
(8,644 Views)
Solution
Accepted by topic author Nando88

I figured it out. I just have to use a match pattern and change everything before a particular string and the concatenate the after match with that string and the folder destination.

0 Kudos
Message 10 of 10
(8,635 Views)