Как сказать "нет" всем, “Вы хотите перезаписать” подсказки в копии пакетного файла?

Вам нужно просмотреть каждую запись загрузчика класса в пути к классу:

    String pkg = "org/apache/commons/lang";
    ClassLoader cl = ClassLoader.getSystemClassLoader();
    URL[] urls = ((URLClassLoader) cl).getURLs();
    for (URL url : urls) {
        System.out.println(url.getFile());
        File jar = new File(url.getFile());
        // ....
    }   

Если запись является каталогом, просто посмотрите в правый подкаталог:

if (jar.isDirectory()) {
    File subdir = new File(jar, pkg);
    if (!subdir.exists())
        continue;
    File[] files = subdir.listFiles();
    for (File file : files) {
        if (!file.isFile())
            continue;
        if (file.getName().endsWith(".class"))
            System.out.println("Found class: "
                    + file.getName().substring(0,
                            file.getName().length() - 6));
    }
}   

Если запись является файлом, и это jar, проверьте записи ZIP:

else {
    // try to open as ZIP
    try {
        ZipFile zip = new ZipFile(jar);
        for (Enumeration<? extends ZipEntry> entries = zip
                .entries(); entries.hasMoreElements();) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();
            if (!name.startsWith(pkg))
                continue;
            name = name.substring(pkg.length() + 1);
            if (name.indexOf('/') < 0 && name.endsWith(".class"))
                System.out.println("Found class: "
                        + name.substring(0, name.length() - 6));
        }
    } catch (ZipException e) {
        System.out.println("Not a ZIP: " + e.getMessage());
    } catch (IOException e) {
        System.err.println(e.getMessage());
    }
}

Теперь, когда у вас есть все имена классов с пакетом, вы можете попробовать их загрузить и проанализировать, если они классы или интерфейсы и т. д.

54
задан Andy Lester 11 October 2008 в 06:18
поделиться

6 ответов

Если нет сценарий, где Вы были бы не , хотят скопировать существующие файлы в источнике, которые изменились начиная с последней копии, почему бы не использовать XCOPY с/D, не определяя дату?

70
ответ дан Kev 7 November 2019 в 17:39
поделиться

Можно сделать текстовый файл с одной длинной строкой "n", затем выполнить команду и поставить после нее < nc.txt. Я сделал это, чтобы скопировать более 145 000 экземпляров, где "No overwrite" - это то, что я хотел, и это отлично сработало.

Или вы можете просто удерживать клавишу n нажатой чем-нибудь, но это займет больше времени, чем использование команды <, чтобы вставить ее внутрь.

21
ответ дан 7 November 2019 в 07:39
поделиться

Вот обходное решение. Если Вы хотите скопировать все с, который уже не существует в B:

Копия к новому каталогу C. Скопируйте B в C, перезаписав что-либо, что накладывается с A. Скопируйте C в B.

11
ответ дан Liam 7 November 2019 в 17:39
поделиться

Я использую XCOPY со следующими параметрами для копирования блоков.NET:

/D /Y /R /H 

/D:m-d-y - Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.

/Y - Suppresses prompting to confirm you want to overwrite an existing destination file.

/R - Overwrites read-only files.

/H - Copies hidden and system files also.
6
ответ дан WrightsCS 7 November 2019 в 17:39
поделиться

Я ожидаю , xcopy имеет опция для этого.

Бинго:

http://www.xxcopy.com/xxcopy27.htm#tag_231

2.3   By comparison with the file in destination

    The switches in this group select files based on the
    comparison between the files in the source and those in
    the destination.  They are often used for periodic backup
    and directory synchronization purposes. These switches
    were originally created as variations of directory backup.
    They are also convenient for selecting files for deletion.

2.3.1  by Presence/Absence

    The /BB and /U switches are the two switches which select
    files by the pure presence or absence as the criteria.
    Other switches in the this group (Group 2.3) are also
    affected by the file in the destination, but for a
    particular characteristics for comparison's sake.

    /BB  Selects files that are present in source but not in destination.
    /U   Selects files that are present in both source and destination.

-Adam

5
ответ дан WrightsCS 7 November 2019 в 17:39
поделиться

В зависимости от размера и количества скопированных файлов, Вы могли скопировать целевой каталог по источнику сначала с "да ко всем", тогда сделайте оригинал, который Вы делали, также с "да ко всему" набору. Это должно дать Вам те же результаты.

2
ответ дан tloach 7 November 2019 в 17:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: