04-20-2017 07:31 AM
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. ;
data target ;
infile "dir /b ""&target\"" " pipe truncover;
input fname $256. ;
proc sql noprint ;
create table newfiles as
select * from source
where not (upcase(fname) in (select upcase(fname) from target ) )
set newfiles ;
cmd = catx(' ','copy',quote(catx('\',"&source",fname)),quote("&target"));
infile cmd pipe filevar=cmd end=eof ;
do while (not eof);
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
04-20-2017 07:56 AM
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.
04-21-2017 05:35 AM
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.
04-21-2017 06:20 AM
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.
04-20-2017 09:03 AM
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.