0

I want to call rsync from Java using Runtime.exec() and I want to ignore hidden files/folders. The command is simple and works like a charm at the command line.

rsync -r --exclude=".*" source destination

I have tried many, many different combinations of breaking these arguments down correctly to be passed as a String[] to exec(). I have failed and I may be close to losing my mind.

Some examples of what I have tried

String[]{ "rsync", "-r", "--exclude", "=", ".*", source, destination});
String[]{ "rsync", "-r", "--exclude", "=", "\".*\"", source, destination});
String[]{ "rsync", "-r", "--exclude=\".*\"", source, destination});

Most of the time I end up with an exit 23 (which is "partial transfer due to error"), the transfer completes but includes hidden files/folders.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Peter Kelly
  • 14,253
  • 6
  • 54
  • 63
  • 1
    Are you experiencing the problem on Windows or on Unix? The `exclude=".*"` part on Unix is generally handled by the shell and not the program itself. In such a case you could run `sh -c` before your command. – Alex Jun 11 '12 at 10:06
  • @Alex sorry, I should have specified - this is on a machine running Ubuntu. – Peter Kelly Jun 11 '12 at 10:16
  • Have you tried with "--exclude='.*'" or "--exclude=.\\*"? It might work around the shell globbing. – Daniel Voina Jun 11 '12 at 13:23

1 Answers1

1

As said ".*" is evaluated by the shell. Better place all options in a file and do rsync @myfile.

BTW I wonder whether the original command excludes .* directories in subdirectories.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138