Сценарий Powershell для удаления старых файлов

input.nextLine().split(" ");

возвращает String[], вы не можете автоматически привести его к BigInteger[], так как это выдаст ClassCastException.

Вы разрешаете десятичные значения? Если это так, вам лучше преобразовать каждый элемент String в примитивное представление double, поскольку вам не понадобится дополнительная точность, предложенная в BigDecimal.

Поскольку десятичные значения не будут разрешены, вам нужно преобразовать String в его integer представление.

for (final String s : input.nextLine().split(" ")) {
   final int value = Integer.parseInt(s);
   stack.push(value);
}

Универсальный тип стека будет Integer. Итак, Stack<Integer>

Рассматривали ли вы случай неправильного ввода данных пользователем? В этом случае вам нужно обработать NumberFormatException

5
задан Brian Tompsett - 汤莱恩 3 July 2015 в 14:58
поделиться

2 ответа

Хорошо, поехали:

  1. -lt, -le и -gt - операторы сравнения. lt означает меньше, le означает меньше или равно, а gt означает больше чем.

  2. Удаление папок может стать опасным, если вы не контролируете то, что попадает в него. У вас могут возникнуть проблемы, и помните о потере данных. Вы можете удалять папки с помощью того же командлета Remove-Item, просто играя с его параметрами. Проверьте эту статью, в ней есть отличные инструкции, как этого добиться: http://searchwindowsserver.techtarget.com/generic/0,295582,sid68_gci1275887,00.html

  3. Usually, for files that have been sitting there for a while, LastWriteTime and CreatedDate and LastAccessTime will be the same. In a read-only file, like a DLL, LastAccessTime might be newer than the other two. In a read/write file (like outlook's pst file) WriteTime and AccessTime might be the same. Basically, that's totally up to you. They work as the same way as LastWriteTime does. Consider the nature of the files you want to delete, and go ahead!

9
ответ дан 13 December 2019 в 05:41
поделиться

The -lt -le and -gt are comparison operators instead of <, <=, >. Type "help about_Comparison_Operators" at the powershell command prompt for the details on each type and the reason for using these instead of the ones you are familiar with from other languages.

To delete folders as well you need to remove the !$.PsIsContainer AND part of the where filter. This is removing all items from the lists that are directories.

I'm not sure what you are after with the question "what about CreatedDate or LastAccessed time" but you can simply use these properties in a similar way as LastWriteTime but you need to decide on the logic you are trying to achieve.

3
ответ дан 13 December 2019 в 05:41
поделиться
Другие вопросы по тегам:

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