blob: b23461f23bf9c9cb856e2e276caf6b7792cbaac9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.jdk.core.util.io;
import java.io.File;
import java.io.IOException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
/**
* @author Ryan D. Brooks
*/
public class MultipleLinks {
public static void main(String[] args) throws IOException {
if (args.length < 3) {
System.out.println("Usage: java tc.MultipleLinks <file to link> <directory for links> <# of links>");
return;
}
link(new File(args[0]), new File(args[1]), Integer.parseInt(args[2]));
}
public static void link(File fileToLink, File directory, int linkCount) throws IOException {
if (!fileToLink.isFile()) {
throw new IllegalArgumentException(fileToLink + " is not a file.");
}
fileToLink = fileToLink.getCanonicalFile();
directory = directory.getCanonicalFile();
if (directory.mkdir()) {
System.out.println("Created " + directory);
}
//separate exstension and file name
String fileName = fileToLink.getName();
String extension = "";
int pos = fileName.lastIndexOf('.');
if (pos != -1) {
extension = fileName.substring(pos);
}
fileName = Lib.removeExtension(fileToLink.getName());
String command = "ln -s " + fileToLink.getPath() + " " + directory.getPath() + File.separator + fileName;
for (int i = 0; i < linkCount; i++) {
Lib.handleProcess(Runtime.getRuntime().exec(command + i + extension));
}
}
}
|