How to list only document name and date using dir command?

Asked

Viewed 715 times

0

How to generate a csv file listing only the name and date of the files within a given directory.

Since there is no option in the command dir, that generates me an output with only this data.

Most bring a header and file size.

I’m using was command:

dir "\\diretorio_origem\*.pdf"  > \\diretorio_destino\lista_arquivos.csv

1 answer

1


  • Update: using forfiles to obtain date and filename:
forfiles /m *.* /c "cmd /c echo/@fdate;@file"

  • Results: 16-04-2019,"Arquivos.ext"

The command could be a dir + a double for, and using the delimiter configured in the system...

Why it happens that a file CVS, has one the following layout:

  • dado+delimitador+dado... | getting: | 01/01/2001;nome_arquivo.ext
:: para identificar/ler o delimitador configurado no sistema (para caso o usuário tenha alterado) via linha de comando ::
set _hkey=HKCU\Control Panel\International  & for /f "tokens=3 delims= " %i in ('reg query "%_hkey%" ^| findstr /lc:"sList"') do set _delimitador=%i

:: para identificar o delimator configurado via bat ::
set _hkey=HKCU\Control Panel\International
for /f "tokens=3 delims= " %%i in ('reg query "%_hkey%" ^| findstr /lc:"sList"') do set _delimitador=%%i

:: na linha de comando ::
type nul > \\diretorio_destino\lista_arquivos.csv & set _hkey=HKCU\Control Panel\International  & for /f "tokens=3delims= " %D in ('reg query "%_hkey%" ^| findstr /lc:"sList"')do for /f "tokens=1,5delims= " %i in ('dir /tc /a-d^|find "/"')do echo/%i%D%j>>\\diretorio_destino\lista_arquivos.csv 

:: no arquivo bat ::
type nul > \\diretorio_destino\lista_arquivos.csv & set _hkey=HKCU\Control Panel\International  & for /f "tokens=3delims= " %%D in ('reg query "%_hkey%" ^| findstr /lc:"sList"')do for /f "tokens=1,5delims= " %%i in ('dir /tc /a-d^|find "/"')do echo/%%i%%D%%j>>\\diretorio_destino\lista_arquivos.csv 
  • Results: 16/04/2019;Arquivos.ext

Browser other questions tagged

You are not signed in. Login or sign up in order to post.