BookmarkSubscribeRSS Feed
LineMoon
Lapis Lazuli | Level 10

@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, ...

 

 

 

 

Tom
Super User Tom
Super User

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.

LineMoon
Lapis Lazuli | Level 10

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)

Tom
Super User Tom
Super User

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;

 

LineMoon
Lapis Lazuli | Level 10

Thank tou Tom

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 19 replies
  • 2752 views
  • 4 likes
  • 5 in conversation