Hello
I want to copy all the files from one folder to another folder
for ex-C:\old folder
I want all the the folder and file to be copied from old folder to new folder in the C drive
I am using below code
let source=c:\old folder ;
%let target=c:\new folder ;
data source ;
infile "dir /b ""&source\"" " pipe truncover;
input fname $256. ;
run;
data target ;
infile "dir /b ""&target\"" " pipe truncover;
input fname $256. ;
run;
proc sql noprint ;
create table newfiles as
select * from source
where not (upcase(fname) in (select upcase(fname) from target ) )
;
quit;
data _null_;
set newfiles ;
cmd = catx(' ','copy',quote(catx('\',"&source",fname)),quote("&target"));
infile cmd pipe filevar=cmd end=eof ;
do while (not eof);
input;
put _infile_;
end;
run;
the problem that I am facing is that
a) if there is folder called great and inside it has file new.txt in C;\old folder then it copies in new path as new.txt but it can not creates new.txt in a folder called great
b) If I run my above program again it does not replace the file with the new one
please let em know how can I acheive ths
Since you have commandline access (XCMD) anyway, use xcopy. Much easier.
And your problem b) is caused by the condition in your proc sql, which explicitly excludes files that already exist in target.
How can I do this thing through XCOPY .could you help me out ?
In SAS:
x 'copy "<path>" "<topath>"';
It is using the Operating System copy command.
Do bear in mind per my previous post, if the folders exist, you dont have access, something is open within them and any other number of things the process will fail - hence why I again suggest you fix your process rather than try to use a third party tool to do this.
@Rohit12 wrote:
How can I do this thing through XCOPY .could you help me out ?
Gosh, you young padawans are so helpless at times!
Google for "Windows xcopy reference", and follow the links. The first one will be the MS reference page from Windows XP with lots of examples; I take it that not much has changed since then.
The question arises to me, why? SAS is not the best tool for operating system management, it can do it, but if your doing that in a third party tool questions should be jumping to mind as to why. Why those folders, do they need to be empty? If they are duplicating, again why, if its datasets, you can do that in datastep, if its other files what else is going wrong to make you waant to copy them etc.
If you just need a fixed structure, you would be bettter off writing a small batch file to populate it.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.