Компьютерный форум OSzone.net  

Компьютерный форум OSzone.net (http://forum.oszone.net/index.php)
-   Хочу все знать (http://forum.oszone.net/forumdisplay.php?f=23)
-   -   проблема удаления множества файлов с длинным путем (http://forum.oszone.net/showthread.php?t=293803)

kupall 12-01-2015 17:46 2455009

проблема удаления множества файлов с длинным путем
 
Добрый день!
нужно на файловом хранилище (огромная куча папок и подпапок) удалить все файлы определенного типа
вот пример того что забиваю в командную строку
cd /d C:\files
del /s /q *.doc
но на некоторых файлах с длинным путем, вся операция прекращается и дальше не идет, пока проблемный файл не будет удален вручную.
но таких длинных файлов очень много и вручную уже не поудаляешь.
есть ли какое-нибудь решение?

MKN 12-01-2015 18:03 2455020

kupall,
попробуй работать с короткими именами (преобразуй длинные)

mwz 12-01-2015 23:16 2455178

kupall, а что,

cmd /c Del /S /Q /A \\.\C:\files\*.doc

(начало до Del – для возможности запуска команды не в окне CMD, а по Win+R, и в батнике не нужно. Ключ /A – для удаления в т.ч. скрытых файлов) тоже не работает?

kupall 13-01-2015 11:31 2455315

все равно не получилось, застревает на одном файле и прекращает операцию
а что означает выражение \\.\ а то нагуглить не получается

Iska 13-01-2015 12:26 2455349

Цитата:

Цитата kupall
а что означает выражение \\.\ а то нагуглить не получается »

Naming Files, Paths, and Namespaces (Windows):
Скрытый текст
Цитата:



Win32 Device Namespaces

The "\\.\" prefix will access the Win32 device namespace instead of the Win32 file namespace. This is how access to physical disks and volumes is accomplished directly, without going through the file system, if the API supports this type of access. You can access many devices other than disks this way (using the CreateFile and DefineDosDevice functions, for example).

For example, if you want to open the system's serial communications port 1, you can use "COM1" in the call to the CreateFile function. This works because COM1–COM9 are part of the reserved names in the NT namespace, although using the "\\.\" prefix will also work with these device names. By comparison, if you have a 100 port serial expansion board installed and want to open COM56, you cannot open it using "COM56" because there is no predefined NT namespace for COM56. You will need to open it using "\\.\COM56" because "\\.\" goes directly to the device namespace without attempting to locate a predefined alias.

Another example of using the Win32 device namespace is using the CreateFile function with "\\.\PhysicalDiskX" (where X is a valid integer value) or "\\.\CdRomX". This allows you to access those devices directly, bypassing the file system. This works because these device names are created by the system as these devices are enumerated, and some drivers will also create other aliases in the system. For example, the device driver that implements the name "C:\" has its own namespace that also happens to be the file system.

APIs that go through the CreateFile function generally work with the "\\.\" prefix because CreateFile is the function used to open both files and devices, depending on the parameters you use.

If you're working with Windows API functions, you should use the "\\.\" prefix to access devices only and not files.

Most APIs won't support "\\.\"; only those that are designed to work with the device namespace will recognize it. Always check the reference topic for each API to be sure.

NT Namespaces

There are also APIs that allow the use of the NT namespace convention, but the Windows Object Manager makes that unnecessary in most cases. To illustrate, it is useful to browse the Windows namespaces in the system object browser using the Windows Sysinternals WinObj tool. When you run this tool, what you see is the NT namespace beginning at the root, or "\". The subfolder called "Global??" is where the Win32 namespace resides. Named device objects reside in the NT namespace within the "Device" subdirectory. Here you may also find Serial0 and Serial1, the device objects representing the first two COM ports if present on your system. A device object representing a volume would be something like "HarddiskVolume1", although the numeric suffix may vary. The name "DR0" under subdirectory "Harddisk0" is an example of the device object representing a disk, and so on.

To make these device objects accessible by Windows applications, the device drivers create a symbolic link (symlink) in the Win32 namespace, "Global??", to their respective device objects. For example, COM0 and COM1 under the "Global??" subdirectory are simply symlinks to Serial0 and Serial1, "C:" is a symlink to HarddiskVolume1, "Physicaldrive0" is a symlink to DR0, and so on. Without a symlink, a specified device "Xxx" will not be available to any Windows application using Win32 namespace conventions as described previously. However, a handle could be opened to that device using any APIs that support the NT namespace absolute path of the format "\Device\Xxx".

With the addition of multi-user support via Terminal Services and virtual machines, it has further become necessary to virtualize the system-wide root device within the Win32 namespace. This was accomplished by adding the symlink named "GLOBALROOT" to the Win32 namespace, which you can see in the "Global??" subdirectory of the WinObj browser tool previously discussed, and can access via the path "\\?\GLOBALROOT". This prefix ensures that the path following it looks in the true root path of the system object manager and not a session-dependent path.


Для общего обзора также имеет смысл: How NTFS Works: Local File Systems.

Iska 13-01-2015 12:41 2455363

kupall, я бы ещё попробовал volume'овский префикс \\?\<Volume GUID>\<Very long path>. Т.е., сначала определяете ссылку посредством «mountvol.exe»:
Код:

mountvol.exe c: /l
Затем пробуете использовать её в виде:
Код:

del /s /q /a "\\?\Volume{19a771ac-c879-11df-867c-806dbcd2696f}\files\*.doc"
Разумеется, вместо выделенного подставьте Volume GUID Вашего тома.

Vadikan 13-01-2015 16:00 2455475

Вдобавок Как обойти ограничение на длину пути при создании или копировании файла (и удаления тоже)

Iska 13-01-2015 17:08 2455520

Vadikan, в данном случае проблема не в том, как сделать, а в том, как сделать массово. Так-то можно хоть subst пользовать для сокращения пути.

DJ Mogarych 14-01-2015 00:36 2455715

Robocopy умеет работать со сверхдлинными путями файлов. Robocopy встроен во все более-менее свежие системы Windows.
Создайте пустую папку и синхронизируйте с той папкой, где файлы нужно удалить. (ключ, кажется, называется /MIR)

синтаксис

Iska 14-01-2015 02:10 2455731

DJ Mogarych, мне что-то не удаётся составить корректный синтаксис с маской — удаляется всё, отсутствующее в назначении.

DJ Mogarych 19-01-2015 22:44 2458579

Переместите их в другую папку, а там удалите:
Код:

ROBOCOPY sourcedir destdir *.avi *.doc /mov
del /s /q destdir\*



Время: 00:10.

Время: 00:10.
© OSzone.net 2001-