查找 pdfs/doc/docx/etc 的批處理文件 (Batch file to look for pdfs/doc/docx/etc)


問題描述

查找 pdfs/doc/docx/etc 的批處理文件 (Batch file to look for pdfs/doc/docx/etc)

尋求腳本的幫助,以在 c:\users\ 下的所有文件夾中搜索 .pdf、.doc、.docx 等。我正在清理一些帶有文件的計算機,但我不想刪除用戶文件夾大部分只是他們的內容。這適用於用戶不應將任何內容保存到硬盤驅動器的醫師辦公室,我已實施不保存政策,但希望關閉並保存現有數據以備將來參考。

將在 50 多台計算機上的服務器上使用 psexec 運行。如果可能的話,我希望輸出是 \servername\destinationfolder\computername\username\file.pdf 或類似的東西,所以我知道文檔來自哪台計算機和用戶。

我認為它看起來像像這樣使用 robocopy,但它似乎不起作用。<


參考解法

方法 1:

You're using the FOR command incorrectly, but I think you don't need it at all. The following should cut it as it recurses through every subdirectory beneath c:\users, collects the specified files (add extensions as you like) and then copies them to the specified destination.

ROBOCOPY c:\users \\servername\destinationfolder *.pdf *.doc *.docx /XJD /S

Edit: As it turned out, OP is using a newer version of Windows than XP and this fact requires the /XJD switch to be added, which...

...will prevent Directory Junction Points from being parsed. This avoids a nasty recursion issue that can sometimes occur with Windows' "fake" directories such as "Documents and Settings"

Edit for completeness: Motivated by @aschipfl, here's a pointer on what's wrong with the FOR command ‑ FOR /F is used in a quite different way. As you wanted to iterate over all the directories of a single level of the filesystem, you could for example do:

FOR /D %%D IN ( c:\users\* ) DO ( ... )

But, when approaching the task like this, you cannot easily create the directory structure like ROBOCOPY does without writing quite a lot of code, and that's just unnecessary when the solution can be as simple as the one above.

(by MackManzb226)

參考文件

  1. Batch file to look for pdfs/doc/docx/etc (CC BY‑SA 2.5/3.0/4.0)

#list #batch-file #search






相關問題

Python 讀取 txt 文件作為輸入:IndexError: list index out of range? (Python read txt file as input: IndexError: list index out of range?)

danh sách trong python, vòng lặp for, mảng (list in python, loop for, array)

查找 pdfs/doc/docx/etc 的批處理文件 (Batch file to look for pdfs/doc/docx/etc)

如何在python中將所有負數更改為零? (How do I change all negative numbers to zero in python?)

從Scala中的列表返回元素 (Returning an element from a List in Scala)

如何在共享點列表中指定定義的排序 (How do you specify a defined sort in sharepoint list)

在 Mathematica 中將列表元素連接成一個數字 (Concatenate list elements into a number in Mathematica)

如何從 javascript 對像中獲取名稱和值到新列表中? (How to get name and values from a javascript object into a new list?)

Kivy:如何使用 RecycleView 在 Kivy 中顯示具有可變行的列表? (Kivy: how to display a list with variable rows in Kivy with a RecycleView?)

無法正確對齊列表中的中間文本 (Can't get middle text in list aligned correctly)

在 Python 列表中查找位於特定字符串之間的字符串 (Find Strings Located Between Specific Strings in List Python)

有沒有辦法在 Python 中使用變量中的字符串調用方法? (Is there a way to call a method in Python using a string inside a variable?)







留言討論