Mercurial Hosting > luan
changeset 1795:745f756e719b
make copy_to recursive
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 02 Jan 2024 21:49:54 -0700 |
parents | 04ac5f2771c8 |
children | 383703b581bc |
files | src/goodjava/io/IoUtils.java src/luan/modules/IoLuan.java |
diffstat | 2 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
diff -r 04ac5f2771c8 -r 745f756e719b src/goodjava/io/IoUtils.java --- a/src/goodjava/io/IoUtils.java Sat Dec 30 18:41:35 2023 -0700 +++ b/src/goodjava/io/IoUtils.java Tue Jan 02 21:49:54 2024 -0700 @@ -48,6 +48,15 @@ return Files.isSymbolicLink(file.toPath()); } + public static void copyRecursively( File from, File to ) throws IOException { + copy(from,to); + if( from.isDirectory() && !isSymbolicLink(from) ) { + for( File f : from.listFiles() ) { + copyRecursively( f, new File(to,f.getName()) ); + } + } + } + public static void deleteRecursively(File file) throws IOException { if( file.isDirectory() && !isSymbolicLink(file) ) { for( File f : file.listFiles() ) {
diff -r 04ac5f2771c8 -r 745f756e719b src/luan/modules/IoLuan.java --- a/src/luan/modules/IoLuan.java Sat Dec 30 18:41:35 2023 -0700 +++ b/src/luan/modules/IoLuan.java Tue Jan 02 21:49:54 2024 -0700 @@ -455,7 +455,7 @@ File dest = objToFile(luan,destObj); if( dest==null ) throw new LuanException( "bad argument #1 to 'copy_to' (string or file table expected)" ); - IoUtils.copy(file,dest); + IoUtils.copyRecursively(file,dest); } public void link_from(Luan luan,Object linkObj) throws LuanException, IOException {