Nur ADS-Dateien anzeigen

554
user196661

Derzeit ist der Code, den ich mit Alternate Data Stream (ADS) Dateien in zeigen cmd.exeist dir /R.

Dies führt jedoch dazu, dass zusätzlich zu den ADS-Dateien alle meine anderen Dateien aufgelistet werden.

Die Frage ist - welchen Befehl sollte ich verwenden, um nur ADS-Dateien anzuzeigen.


Der Befehl dir C:\ /r /s | findstr /r "\$DATA"ist der beste, den ich finden kann - obwohl ich mit seiner Genauigkeit nicht allzu überzeugt bin. Irgendwelche anderen?

1

2 Antworten auf die Frage

1
Greck

Das AltStreamDump- Dienstprogramm (von Nirsoft) kann dies auch tun.

BEARBEITEN: Es gibt auch die GUI-Anwendung AlternateStreamView (auch Nirsoft), die Befehlszeilenunterstützung unterstützt und z. B. das Exportieren einer Liste in eine Datei zulässt

Alle Befehle, für die keine Programme von Drittanbietern installiert werden müssen? user196661 vor 11 Jahren 0
1
dbenham

Very cool - I had never heard of ADS before, and had to look up what it was.

I can't vouch for how reliable your method is, but I can see three ways to potentially improve it.

1) A normal file could be named "$DATA". You can improve the accuracy of your filter by using:

findstr /el :$DATA 


2) You lose the path information when you use DIR /R /S option and keep only the :$DATA lines. Here is a nasty one liner that lists the file size and full path for all ADS. I redirect stderr to nul to hide error messages from inaccessible folders:

for /r %F in (.) do @(pushd "%F"&&(for /f "tokens=1*" %A in ('dir /r^|findstr /el :$DATA') do @echo %A %~fB)&popd)2>nul 


3) An ADS can be attached to a folder as well as a file. Suppose the following folder structure exists: C:\root\child\grandchild\. Also suppose that C:\root\child has an ADS named child:ads.txt. The DIR /R /S command will list the ADS at the following three levels:

  • C:\root will list child:ads.txt:$DATA

  • C:\root\child will list .:ads.txt:$DATA

  • C:\root\grandchild will list ..:ads.txt:$DATA

Only the first listing is wanted. Within the FOR /F loop, the size of %B can be gotten by using %~zB, but that only works for the first listing; it expands to an empty string for the other two. That provides a convenient and efficient way to eliminate the unwanted listings.

for /r %F in (.) do @(pushd "%F"&&(for /f "tokens=1*" %A in ('dir /r^|findstr /el :$DATA') do @if .%~zB neq . echo %A %~fB)&popd)2>nul 


The final solution looks much better as a multi-line batch script

@echo off for /r %%F in (.) do ( pushd "%%F" &&( for /f "tokens=1*" %%A in ( 'dir /r^|findstr /el :$DATA' ) do if "%%~zB" neq "" echo %%~zB %%~fB popd ) )2>nul 


Simply remove %%A (or %A) from the ECHO command if you only want the ADS file paths without the file sizes.

Das einzige Problem ist, dass alternative Streams einen beliebigen Namen haben können. Daher müssen Sie nach Dateinamen suchen, die Doppelpunkte enthalten. afrazier vor 11 Jahren 0
@afrazier - Ich verstehe deine Logik nicht. Mit dem Befehl DIR / R wird an den aufgelisteten Namen aller ADS ": $ DATA" angehängt, und meine Lösung sucht nach genau dieser Endzeichenfolge. Der Name des ADS hat keinen Einfluss auf das Ergebnis. Ein ADS mit dem Namen `file.txt: hidden.txt` wird beispielsweise als` file.txt: hidden.txt: $ DATA` aufgeführt. dbenham vor 11 Jahren 0
Windows-Dateinamen dürfen kein `:` enthalten. aphoria vor 11 Jahren 0
@dbenham: Sorry, I thought that $DATA was the stream name. In that case, your scripts look like just the thing then. afrazier vor 11 Jahren 0