带属性为CSV批目录 [英] Batch Directory with Attributes into csv
问题描述
我已经花了很多时间量好本搜索(及其他)网站试图弄清楚这一点,但我终于承认,我卡住了。我是一个初学者用户,所以我提前如果我的术语/解释是混乱表示歉意。
操作系统:Windows 7
我工作在一个批处理文件,将创建一个批处理文件的当前文件夹位置的所有文件夹和文件(包括子文件夹)属性和路径的.csv文件。我这个迭代的属性的所有可能出现的情况。下面是我的code的说明:
**创建csv文件标题:
上@echo
回声文件夹与文件,隐藏,系统文件夹,只读,路径和GT; FoldersAndFilesWithAttributes.csv
**具有特定属性的复制文件和文件夹的名称到一个临时的.txt文件
DIR%〜DP0 / S / N / A:DHSR / B>> FoldersAndFiles.txt
**属性的文件夹/文件的路径和地方追加到一个CSV文件
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,隐藏,系统,只读,我%%>> FoldersAndFilesWithAttributes.csv
**删除临时.txt文件
德尔FoldersAndFiles.txt
问题(S)
我不完全肯定这个问题(S)是因为 - 由于某种原因 - 它在某些文件夹,而不是其他。有时候,我只得到了标题时,与已知的属性的文件是present,有时完整路径是不是present,有时我什么都得不到。我想也许我太迅速覆盖临时文件,所以我创建了独特的.txt文件每个场景,但是这仍然没有奏效。
**下面是我的全code:
关闭@echo回声文件夹与文件,隐藏,系统文件夹,只读,路径和GT; FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:DHSR / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,隐藏,系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:DHS-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,隐藏,系统,只读不,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:DH-SR / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,隐藏,不系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:DH-S-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,隐藏的,不系统,而不是只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:D-HSR / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,不隐藏,系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:D-HS-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,不隐藏,系统,只读不,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:D-H-SR / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,不隐藏,不系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:D-H-S-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件夹,不隐藏,不系统,而不是只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-dhsr / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,隐藏,系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-dhs-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,隐藏,系统,只读不,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-dh-SR / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,隐藏,不系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-dh-S-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,隐藏的,不系统,而不是只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-d-HSR / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,而不是隐藏,系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-d-HS-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,而不是隐藏,系统,只读不,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-d-H-SR / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,不隐藏,不系统,只读,我%%>> FoldersAndFilesWithAttributes.csvDIR%〜DP0 / S / N / A:-d-H-S-R / B>> FoldersAndFiles.txt
FOR / F令牌= *%% i的(FoldersAndFiles.txt)做回声文件,不隐藏,不系统,而不是只读,我%%>> FoldersAndFilesWithAttributes.csv
德尔FoldersAndFiles.txt
感谢您的帮助,
肖恩
> FoldersAndFilesWithAttributes.csv(FOR / Fdelims =%%我在('
DIR / S / B / A%〜DP0 *。*')也呼应%%〜AI,我%%)
根据命令行参数(参数):
使用
%〜AI
来显示文件的扩展属性。的
的%%〜AI
识别9 NTFS文件属性。文件属性的扩展
生产的系列9破折号,每个识别的属性
取代以字母破折号。有没有公认的属性的文件
或者没有设置将扩大到9破折号像这样:---------
块引用>属性扩展
FILE_ATTRIBUTE_DIRECTORYÐ--------
FILE_ATTRIBUTE_READONLY -r -------
FILE_ATTRIBUTE_ARCHIVE --a ------
FILE_ATTRIBUTE_HIDDEN --- ^ h -----
FILE_ATTRIBUTE_SYSTEM ---- ----小号
FILE_ATTRIBUTE_COM preSSED -----Ç---
FILE_ATTRIBUTE_OFFLINE ------ O--
FILE_ATTRIBUTE_TEMPORARY ------- T-
FILE_ATTRIBUTE_REPARSE_POINT --------升
FILE_ATTRIBUTE_NORMAL ---------您可以作出的准确的
CSV
页眉如下(与文件掩码修改,以缩小输出到合理的大小):@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
>文件\\ FoldersAndFilesWithAttributes.csv(
REM CSV标题
回声D,R,一个,H,S,C,O,T,升,文件
REM CSV行
FOR / Fdelims =%%我在('
DIR / S / B / A%〜1 *。*2 ^>讷
')做呼叫:显示%%〜爱我%%
)ENDLOCAL
GOTO:EOF:显示
::子例程来显示文件属性为csv线
::%1文件属性---------
::%2文件名
设置ATTR =%〜1
设置走出=%ATTR:〜0.1%
设置出来=%出来%,%ATTR:〜1.1%
设置出来=%出来%,%ATTR:2,1〜%
设置出来=%出来%,%ATTR:〜3,1%
设置出来=%出来%,%ATTR:4,1〜%
设置出来=%出来%,%ATTR:〜5.1%
设置出来=%出来%,%ATTR:6,1〜%
设置出来=%出来%,%ATTR:7,1〜%
设置出来=%出来%,%ATTR:〜8.1%
设置出来=%出来: - =%
回声%出来%,%〜2
GOTO:EOF输出
D:\\球棒GT; D:\\ BAT \\ SO \\ 31079628new.bat *新D:\\球棒GT;类型的文件\\ FoldersAndFilesWithAttributes.csv
D,R,一个,H,S,C,O,T,升,文件
,,一个,,,,,,,D:\\蝙蝠\\文件\\ pathnew.txt
,R,A,,,,,,,D:\\ BAT \\文件\\布布\\新建文本文档.txt
,,一个,H,,,,,,D:\\蝙蝠\\文件\\数字\\新建文本文档
,,一个,,,,,,,D:\\蝙蝠\\ SO \\ 28526273new
,,一个,,,,,,,D:\\蝙蝠\\ SO \\ 31079628new.bat
D,,,,,,,,,D:\\蝙蝠\\ SO \\新建文件夹
,,一个,,,C,,,,D:\\蝙蝠\\ SU \\新建文本文档D:\\球棒GT;I've spent a good amount of time searching this (and other) websites trying to figure this out, but I finally admit that I'm stuck. I'm a beginner user, so I apologize in advance if my terminology / explanation is confusing.
OS: Windows 7
I'm working on a single batch file that will create a .csv file with attributes and paths for all folders and files (including subfolders) of the batch file's current folder location. I'm iterating this for all possible scenarios of the attributes. Below is an explanation of my code:
**create a heading in the csv file:
@echo on echo Folder vs. File,Hidden,System Folder,Read Only,Path > FoldersAndFilesWithAttributes.csv
**copy file and folder names with specific attributes to a temporary .txt file
dir %~dp0 /s /n /a:dhsr /b >> FoldersAndFiles.txt
**append the attributes to the folder / file path and place into a csv file
for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Hidden,System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv
**delete temporary .txt file
del FoldersAndFiles.txt
The Problem(s) I'm not exactly sure where the problem(s) are because - for some reason - it works in certain folders, but not others. Sometimes I only get the heading when files with known attributes are present, sometimes the full path is not present, and sometimes I get nothing at all. I thought maybe I was overwriting the temporary file too quickly, so I created unique .txt files for each scenario, but that still didn't work.
**Below is my full code:
@echo off echo Folder vs. File,Hidden,System Folder,Read Only,Path > FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:dhsr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Hidden,System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:dhs-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Hidden,System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:dh-sr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Hidden,Not System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:dh-s-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Hidden,Not System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:d-hsr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Not Hidden,System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:d-hs-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Not Hidden,System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:d-h-sr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Not Hidden,Not System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:d-h-s-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo Folder,Not Hidden,Not System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-dhsr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Hidden,System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-dhs-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Hidden,System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-dh-sr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Hidden,Not System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-dh-s-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Hidden,Not System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-d-hsr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Not Hidden,System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-d-hs-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Not Hidden,System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-d-h-sr /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Not Hidden,Not System,ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv dir %~dp0 /s /n /a:-d-h-s-r /b >> FoldersAndFiles.txt for /f "tokens=*" %%i in (FoldersAndFiles.txt) do echo File,Not Hidden,Not System,Not ReadOnly,%%i >> FoldersAndFilesWithAttributes.csv del FoldersAndFiles.txt
Thanks for your help, Sean
解决方案> FoldersAndFilesWithAttributes.csv (for /f "delims=" %%I in (' dir /S /B /A "%~dp0*.*"') do echo %%~aI,"%%I")
As per Command Line arguments (Parameters):
Use
%~aI
to display the Extended Attributes of a file.FOR
's%%~aI
recognizes 9 NTFS file attributes. The expansion of a file attribute produces a series of 9 dashes, with each recognized attribute replacing a dash with a letter. A file with no recognized attributes or with none set will expand to 9 dashes like this:---------
Attribute Expansion FILE_ATTRIBUTE_DIRECTORY d-------- FILE_ATTRIBUTE_READONLY -r------- FILE_ATTRIBUTE_ARCHIVE --a------ FILE_ATTRIBUTE_HIDDEN ---h----- FILE_ATTRIBUTE_SYSTEM ----s---- FILE_ATTRIBUTE_COMPRESSED -----c--- FILE_ATTRIBUTE_OFFLINE ------o-- FILE_ATTRIBUTE_TEMPORARY -------t- FILE_ATTRIBUTE_REPARSE_POINT --------l FILE_ATTRIBUTE_NORMAL ---------
You could make an accurate
csv
with headers as follows (with filemask modified to narrow down output to reasonable size):@ECHO OFF SETLOCAL enableextensions > files\FoldersAndFilesWithAttributes.csv ( rem csv header echo "d","r","a","h","s","c","o","t","l","file" rem csv lines for /f "delims=" %%I in (' dir /S /B /A "%~1*.*" 2^>Nul ') do call :display "%%~aI" "%%I" ) ENDLOCAL goto :eof :display :: subroutine to display file attributes as csv line :: %1 file attributes --------- :: %2 file name set "attr=%~1" set "out="%attr:~0,1%"" set "out=%out%,"%attr:~1,1%"" set "out=%out%,"%attr:~2,1%"" set "out=%out%,"%attr:~3,1%"" set "out=%out%,"%attr:~4,1%"" set "out=%out%,"%attr:~5,1%"" set "out=%out%,"%attr:~6,1%"" set "out=%out%,"%attr:~7,1%"" set "out=%out%,"%attr:~8,1%"" set "out=%out:-=%" echo %out%,"%~2" goto :eof
Output
d:\bat>D:\bat\SO\31079628new.bat *new d:\bat>type files\FoldersAndFilesWithAttributes.csv "d","r","a","h","s","c","o","t","l","file" "","","a","","","","","","","d:\bat\files\pathnew.txt" "","r","a","","","","","","","d:\bat\files\bubu\New Text Document.txt" "","","a","h","","","","","","d:\bat\files\numeric\New Text Document.txt" "","","a","","","","","","","d:\bat\SO\28526273new" "","","a","","","","","","","d:\bat\SO\31079628new.bat" "d","","","","","","","","","d:\bat\SO\New folder" "","","a","","","c","","","","d:\bat\SU\New Text Document.txt" d:\bat>
这篇关于带属性为CSV批目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!