LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

copyfolder

Solved!
Go to solution

How about two lines of code?

 

    system ("cmd /c attrib -r b:\*.*);          // Remove the read-only protection flag

    system ("cmd /c copy /y a:\a\*.*  b:\");    // Suppress the 'YES' dialogue on the copy

 

As a refinement you could of course programmatically create the strings to be passed to the system() function.

 

JR

0 Kudos
Message 11 of 21
(1,881 Views)

If you want to perform the copy without actually removing attributes on the destination files you may want to check xcopy command and its options, using it with system () as JR suggested.

In particular you could use /r option which overwrites files with read-only attribute and /k which copies attributes from source to destination files. xcopy is a powerful command that can be tailored in a multitude of ways with its options: use "help xcopy" in a dos window to have a list of all options.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 12 of 21
(1,878 Views)

Hi, JR and Roberto

 

 thanks very much for you suggestion. it looks dos commands are still  very powerful Smiley Very Happy

 

however,  i tested those command and i find that command system may only checking the syntax of command string. i did a simple test . just set the deny access in destination folder for specified login user name.  i did not get any error or even warning while copy . how can we deal with this one ?

 

 

B.R

Gerry

0 Kudos
Message 13 of 21
(1,858 Views)

I must admit that I do not understand you when you say "command system may only checking the syntax of command string" Smiley Surprised

 

What did it happened? Was the copy succesful or not?

Which command have you issued? Can you post it here?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 14 of 21
(1,849 Views)

i think i have described in previous post , however, it may not so clear.

 

my question is this once i set the acess permission for destination folder.  copy will be failed. however, command system does not give any error. the return value is "0".   so my question is  how can we check the copy is sucess or failed.

 

Err = system ("cmd /c xcopy /y/r/k D:\\1\\*.*  d:\\2\\");  

 

 

B.R

Gerry

0 Kudos
Message 15 of 21
(1,842 Views)

Well, xcopy may return an error that you may trap in a batch file by testing ERRORLEVEL condition...

Or you may redirect the output of the fuction to a file and read back it...

Both of them are not clean and good methods I'm afraid!

 

Digging with file system permissions is a completely different thing than dealing with read-only attributes and a notably harder beast to beat. Moreover, you may be forced to run your program with administrative privileges to modify permissions in the file system even if using low level windows APIs.

 

Looking at your problem from a different point of view, access privileges on a folder are normally not subject to rapid changes, so you may probably test them at the beginning of your program by copying a dummy file to the destination folder with CopyFile and checking function return value, prompting the user with a descriptive message in case of errors and leaving him to interactively correct the situation before your program may run (he may need to call IT admins to proceed).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 16 of 21
(1,832 Views)

Thanks Roberto.  acturally, file permission is not the problem in my application. because my program is running administion level.  however, i just curious about how can we get error.  however, in other language i saw command copyfolder. but it looks it's not available in C code. even C++.   i did checked MSDN , all samples regards copy folder function are made by JS or VB.

 

 

anyway, this is nice discussing. at least i know i shall not throw away DOS command. some of times there are very useful.  Smiley Very Happy

 

 

B.R

Gerry

0 Kudos
Message 17 of 21
(1,797 Views)

additional input it may useful for some person who will use this function

 

 

when you copy file from other computer. pls careful with below

 

e.g

 

system ("cmd /c xcopy /y/r/k \\commpc\\Douc12\\1\\*.*  d:\\2\\");       does not work. you should type

 

system ("cmd /c xcopy /y/r/k \\\\commpc\\Douc12\\1\\*.*  d:\\2\\"); 

 

 

i donot know the reason behind.  " xcopy /y/r/k \\commpc\\Douc12\\1\\*.*  d:\\2\\"   could work well in DOS . 

 

B.R

gerry

0 Kudos
Message 18 of 21
(1,793 Views)

sorry, i want to post this again. because i found a problem in command xcopy.

 

xcopy do not support space in folder name. e.g.   c:\test data.  

 

with this one. xcopy will be failed.

 

do someone have idea in this part?

 

 

B.R

Gerry

0 Kudos
Message 19 of 21
(1,700 Views)

When you have path with spaces you must embed the full path in quotes for the commands to interpret it correctly: in your case

  xcopy "c:\test data\*.*" k:

will be executed correctly both in a dos window and in system () command.

 

Regarding the previous question, the backslash has a special meaning in c: it can indicate some control code like \n, \t and so on. To indicate a backslach inside a string you must double it. So if you are to use UNC names inside your string, each initial backslash is to be doubled, for a total of 4 backslashes at sting beginning as you have already noted (this also explain why doubling the slashes inside path names is necessary).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 20 of 21
(1,695 Views)