0

I'm using Windows7, and I want to know the number of files (or objects) for comparison to objects in Amazon S3 buckets. I'm not interested in size, as the size can differ between file types.

I want to do this as a list from the command prompt (starting with dir) so that I can output this from several different computers to a spreadsheet so I can verify vs s3. This output out be dir>.txt where the info from dir would not only be date | time | type (directory or file) | filename | plus number of objects.

I have hundreds of folders on dozens of computers to access, so I'm looking for something 1) simple and 2) that doesn't require typing in the name of each folder individually 3) that will search recursively inside each folder and subfolder 4) that generates a list output. The dir command alone is 90% of the way there, it just lacks the number of files inside folders, which hopefully is an easy output to generate.

Please no linux or Powershell recommendations as they can't be applied.

8
  • I suggest that you edit your question, and point out an example of expected output, where it is possible to better understand what you hope to get, once done, I believe you will get a better answer.
    – Io-oI
    Commented Oct 1, 2020 at 23:31
  • Here is an example of the current output from a win7 dir command: 07/30/2020 04:22 PM <DIR> directory1. 07/30/2020 05:07 PM <DIR> directory2. 07/30/2020 04:57 PM <DIR> directory3. Here is what I would like to get—list format for output as a .txt file. 07/30/2020 04:22 PM <DIR> directory1 1000 files. 07/30/2020 05:07 PM <DIR> directory2 1500 files. 07/30/2020 04:57 PM <DIR> directory3 1600 files.
    – Jordan
    Commented Oct 2, 2020 at 21:44
  • get the wc command and do dir /b | wc -l
    – barlop
    Commented Oct 2, 2020 at 23:28
  • Thanks for commenting, I adjusted to what I could understand, if you need to adjust more, please let me know ...
    – Io-oI
    Commented Oct 2, 2020 at 23:30
  • why no Powershell? Vista+ always have powershell included so it should be used instead of the dreaded cmd[
    – phuclv
    Commented Oct 3, 2020 at 1:13

2 Answers 2

0

You can use this command:

@echo off & cd "Filepath" & for /f "tokens=* delims=*" %a in ('dir /s /b') do (set "name=%~fa" & set "date=%~za" & set "type=%~xa" & echo %date% %type% %name% >>"Output.txt")

Here replace "Filepath" with the folder path and output.txt with the output text file. If you need to add more properties, ping me in comment. Run this from Cmd.

1
  • When I run this, all I get is today's date, %type% %name% over and over again. There is no useable information in terms of folder names or number of objects in the folders
    – Jordan
    Commented Sep 29, 2020 at 17:19
0
@echo off & title <nul & title ...\%~nx0

cd/d "%~dp0" && setlocal EnableDelayedExpansion
>nul del/q /f "%temp%\_output_.csv" .\output.csv 2>&1 

for /d /r %%I in (*)do for /f %%i in ('dir/b "%%~I"^|find/c /v ""
')do >>"%temp%\_output_.csv" echo\%%~tI,^<DIR^>,%%~nxI,%%~i,files 

<con: >nul move "%temp%\_output_.csv" .\output.csv 2>&1 & endlocal

Getting a listing of items folders, files, object totals, dates without a predefined layout... is not something that can be easy to achieve, especially when we don't know what is simple for those who ask.

You can try:


@for /d /r %I in (*)do @for /f %i in ('dir/b "%~I\"^|find/c /v ""')do @echo\%~tI ^<DIR^> %~nxI %~i files


@echo off 

rem :: go to your destination folder
cd /d "%~dp0"&& setlocal EnableDelayedExpansion

rem :: remove any files from previous runs (if exist)
>nul del/q /f "%temp%\_output_.csv" .\output.csv 2>&1 

rem :: use a `for` loop to recursively folder and a second loop to
rem :: count your files in the current folder in the first `for` loop
for /d /r %%I in (*)do for /f %%i in ('dir/b "%%~I"^|find/c /v ""
')do >>"%temp%\_output_.csv" echo\%%~tI,^<DIR^>,%%~nxI,%%~i,files 


rem :: save the results to the temporary folder, then move to the current 
<con: >nul move "%temp%\_output_.csv" .\output.csv 2>&1 & endlocal

  • Some options using substitution of for variable:
    %%~i   - expands %%i removing any surrounding quotes (")
    %%~fi  - expands %%i to a fully qualified path name only
    %%~ti  - expands %%i to date/time of file only
    %%~ni  - expands %%i to a file name only
    %%~xi  - expands %%i to a file extension only
    
    %%~nxi => expands %%~i to a file name and extension

  • The option /d /r is undocumented, but can be a useful combination, while it will recurse through all subfolders the wildcard will only match against Folder/Directory names (not filenames).

2
  • Maybe this line in my original post was confusing. Currently dir outputs date | time | type (directory or file) | filename. All I need is for this list to also include number of objects contained in a folder.
    – Jordan
    Commented Oct 1, 2020 at 20:26
  • @Jordan Plz, check last edit... thank you
    – Io-oI
    Commented Oct 2, 2020 at 23:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .