@Tom: what's i mean by "keep the files names in data"?
So , I the ddirectory
D1/file1.txt
/ffile2.txt
/file2.xls
I want to copy D1 in D2
After the "copy" , I want to check the files name have been copied from D1 to D2 in data set check likes this:
Files
file1
file2
filen
As I said, my method give me the right result for copy, ...
If you want to check whether the copy succeeded it is probably easiest to just read the list of files and compare them.
Did you try using the unix command diff. diff -rq D1 D2 will compare directory D1 with directory D2 and report the differences.
Or just read the output of the ls (or ls -R) command into datasets and compare the datasets.
that's correct..We can do that, I have used it before
But the difference is that, with my method, in one action, I can copy and check the files names..
In other methos, I think, I need two actions : action1 : copy( with cp) and action2 : listing the contents(with ls)
Where are you getting the file names now? The cp command you are running will not list the file names. So the data step you are running that is reading form the output of the cp command will read nothing and so have 0 observations.
You could try adding the -v option to the copy command. THen the data step that runs the cp command could read the output and parse it.
To see how that might work let's create a couple and directories with some files and try to copy from one directory to the other.
>mkdir dir1
>mkdir dir2
>touch dir1/file1
>touch dir1/file2
>touch dir1/file3
>touch dir2/file2
>chmod -w dir2/file2
Notice how there should be a problem copying file2 since the target file alread exists and is readonly. Now lets try to copy and see what messages the -v option generates.
>cp -vR dir1/* dir2
`dir1/file1' -> `dir2/file1'
`dir1/file2' -> `dir2/file2'
cp: cannot create regular file `dir2/file2': Permission denied
`dir1/file3' -> `dir2/file3'
So now you could make yourself a data step that reads that output and generates a SAS dataset with the messages.
data files ;
infile 'cp -vR dir1/* dir2' pipe dsd dlm=' ' truncover end=eof;
length success 8 from to $255 dummy $5 ;
drop dummy;
input from dummy to ;
if eof then success=1 ;
else do;
input @@;
success = (_infile_ ^=: 'cp:') ;
if not success then input;
end;
run;
Thank tou Tom
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.