How to get EVERY file in DIR including a file number

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

How to get EVERY file in DIR including a file number

#16 Post by drgt » 04 Dec 2011 06:35

Take more than 3!!

Code: Select all

Directory of G:\Destinator\AuSw\Shields

2011-07-18  14:43    <DIR>          .
2011-07-18  14:43    <DIR>          ..
2009-12-10  19:58               590 Shields.ini
2009-12-10  19:58             3,119 TShield1.png
2009-12-10  19:58             3,025 TShield24.png
2009-12-10  19:58             3,025 TShield25.png
2009-12-10  19:58             3,025 TShield26.png
2009-12-10  19:58             3,564 TShield92.png
2009-12-10  19:58             3,265 TShield93.png
               7 File(s)         19,613 bytes

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: How to get EVERY file in DIR including a file number

#17 Post by !k » 04 Dec 2011 06:49

It's really dir/S ? Not simple "dir" ?

drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

How to get EVERY file in DIR including a file number

#18 Post by drgt » 04 Dec 2011 13:24

confirming dir /a-d /s /b

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: How to get EVERY file in DIR including a file number

#19 Post by !k » 04 Dec 2011 14:02

Image

viewtopic.php?p=11763#p11763 or simple

Code: Select all

setlocal
for /f "tokens=1-3" %%x in ('dir /a-d/s/-c %1 2^>nul ^|findstr /c:"File(s)"') do set "num=%%x"
echo %num% files
endlocal

drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

How to get EVERY file in DIR including a file number

#20 Post by drgt » 04 Dec 2011 14:37

I never thought DIR is so limited..........

Here is the result of your code:

Code: Select all

C:\>setlocal

C:\>for /F "tokens=1-3" %x in ('dir g: /a-d/s/-c 2>nul |findstr /c:"File(s)"') d
o set "num=%x"

C:\>set "num=20"

C:\>set "num=12"

C:\>set "num=10"

C:\>set "num=93"

C:\>set "num=10"

C:\>set "num=44"

C:\>set "num=20"

C:\>set "num=7"

C:\>set "num=1"

C:\>set "num=81"

C:\>set "num=67"

C:\>set "num=30"

C:\>set "num=7"

C:\>echo 7 files
7 files

C:\>endlocal


Remember, we want to get a list of every file complete with its path, and a total number of files at the bottom (1098 files in this case).

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: How to get EVERY file in DIR including a file number

#21 Post by !k » 04 Dec 2011 14:50

Where is Image ?!

AND

20+12+10+93+10+44+20+7+1+81+67+30+7 = 402

drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

How to get EVERY file in DIR including a file number

#22 Post by drgt » 04 Dec 2011 16:22

For some reason can't see the picture you uploaded...

As far as the 402, the total number of files are 1098, not 402!

Obviously there are hidden file/ directories that are not being picked up by dir /a-d /s /b...

xcopy /e /h /l shows 1098 files!

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: How to get EVERY file in DIR including a file number

#23 Post by orange_batch » 04 Dec 2011 16:42

drgt are you changing the scripts? It seems like you changed !k's script from set "num=%%x" to set /a "num+=%%x". The point is to catch the last result from dir, not combine all results.

It shouldn't be possible for the code I wrote to error:

Code: Select all

echo off&echo.&set num=&(for /f "delims=" %a in ('dir /a:-d /b /s') do echo "%~nxa"&set /a num+=1 >nul)&call echo Files: ^%num^%&echo on

It's just not possible. I can only imagine some version of dir that shouldn't exist either, or file table corruption or something.

drgt
Posts: 158
Joined: 21 Sep 2010 02:22
Location: Greece

How to get EVERY file in DIR including a file number

#24 Post by drgt » 04 Dec 2011 17:10

I think I know the answer...
Dir stops at 402 files because it encounters a corrupt file.
Infact, xcopy with the /l switch BUT not with the /c switch also lists 402 files.
When using the /c switch it lists 1098 files!

Correct me if I am wrong.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: How to get EVERY file in DIR including a file number

#25 Post by alan_b » 05 Dec 2011 05:39

Why bother with DIR.
Remove that from you requirement and XCOPY should meet your need.
Try :-
xcopy *.* %TEMP% /L /F /S

Without the /S (avoiding 80,000 files in C:\) I get :-
C:\Users\Alan>xcopy *.* %TEMP% /L /F
C:\Users\Alan\dotnetfolder.txt -> C:\Users\Alan\AppData\Local\Temp\dotnetfolder.txt
C:\Users\Alan\en_res.dll -> C:\Users\Alan\AppData\Local\Temp\en_res.dll
C:\Users\Alan\es_res.dll -> C:\Users\Alan\AppData\Local\Temp\es_res.dll
C:\Users\Alan\fr_res.dll -> C:\Users\Alan\AppData\Local\Temp\fr_res.dll
C:\Users\Alan\grm_res.dll -> C:\Users\Alan\AppData\Local\Temp\grm_res.dll
C:\Users\Alan\it_res.dll -> C:\Users\Alan\AppData\Local\Temp\it_res.dll
C:\Users\Alan\jp_res.dll -> C:\Users\Alan\AppData\Local\Temp\jp_res.dll
C:\Users\Alan\mfc80u.dll -> C:\Users\Alan\AppData\Local\Temp\mfc80u.dll
C:\Users\Alan\Microsoft.VC80.CRT.manifest -> C:\Users\Alan\AppData\Local\Temp\Microsoft.VC80.CRT.manifest
C:\Users\Alan\Microsoft.VC80.MFC.manifest -> C:\Users\Alan\AppData\Local\Temp\Microsoft.VC80.MFC.manifest
C:\Users\Alan\msvcr80.dll -> C:\Users\Alan\AppData\Local\Temp\msvcr80.dll
C:\Users\Alan\PCPE Setup.exe -> C:\Users\Alan\AppData\Local\Temp\PCPE Setup.exe
C:\Users\Alan\PCPE_3.0.1.msi -> C:\Users\Alan\AppData\Local\Temp\PCPE_3.0.1.msi
C:\Users\Alan\PCPE_3.0.msi -> C:\Users\Alan\AppData\Local\Temp\PCPE_3.0.msi
C:\Users\Alan\pt_res.dll -> C:\Users\Alan\AppData\Local\Temp\pt_res.dll
C:\Users\Alan\ResourceReader.dll -> C:\Users\Alan\AppData\Local\Temp\ResourceReader.dll
C:\Users\Alan\ru_res.dll -> C:\Users\Alan\AppData\Local\Temp\ru_res.dll
17 File(s)


Speaking from memory, without the skills of local experts, a script can use something like
FOR /F %%a in ('xcopy *.* %TEMP% /L /F /S') do (
clever-code
)
You then need some "clever-code" to strip out each "->" and the destination path,
and add a preceding incrementing number with each item.

Regards
Alan

Post Reply