Page 1 of 2

Batch file help

Posted: 28 Mar 2012 06:00
by gbeer7
Hi all,

I found this useful batch file which i've amended a little :-

FOR %%? IN (C:\text_files\*) DO (
ECHO File Name Only : %%~n?
ECHO File Extension : %%~x?
ECHO File Size : %%~z?
ECHO File Creation Date :
ECHO Last-Modified Date : %%~t?
ECHO Fully Qualified Path : %%~f?

) >> all.log

What i'm trying to do is get a list of *.mdb and *.mde files.
Also, i've been trying to work out for ages now what the variable for creation date of the file.

Can anyone help me out please ?

Re: Batch file help

Posted: 28 Mar 2012 06:25
by Squashman

Code: Select all

FOR /F "tokens=*" %%G IN ('dir *.mdb *.mde /a-d /b /TC') DO (
ECHO File Name Only : "%%~nG"
ECHO File Extension : "%%~xG"
ECHO File Size : "%%~zG"
ECHO File Creation Date :
ECHO Last-Modified Date : "%%~tG"
ECHO Fully Qualified Path : "%%~fG"

) >> all.log

Not sure about getting the create date. dir /TC gives you the create date but then you have to play around with not use /B switch and then skip lines and parse tokens.

Re: Batch file help

Posted: 28 Mar 2012 06:47
by Squashman
depending on how your file names output from the DIR command you could do something like this.
my dates output like this from the dir command
05/07/07 11:17 AM 35,715 AAABBBCCC01.pdf
03/27/08 04:11 PM 35,973 AAABBBCCC111.pdf

I think this will work.

Code: Select all

for /F "tokens=1-4* delims= " %%G in ('dir /TC /a-d ^|findstr /b /r [0-9][0-9]/[0-9][0-9]') do
ECHO File Name Only : "%%~nK"
ECHO File Extension : "%%~xK"
ECHO File Size : "%%~zK"
ECHO File Creation Date : %%G
ECHO Last-Modified Date : "%%~tK"
ECHO Fully Qualified Path : "%%~fK"

) >> all.log

Re: Batch file help

Posted: 28 Mar 2012 06:47
by foxidrive
This works in XP with 24 hour time.

Code: Select all

@echo off
set flag=
for /f "skip=3 tokens=1-3,*" %%a IN ('dir *.bat *.mdb *.mde /a-d /tc') do (
if /i "%%d"=="bytes" set flag=1
if not defined flag if not "%%d"=="" (
echo File Name            : "%%d"
echo File Extension       : %%~xd
echo File Size            : %%c
echo File Creation Date   : %%a %%b
echo Fully Qualified Path : "%%~fd"
echo.
)
)  >>all.txt
pause

Re: Batch file help

Posted: 28 Mar 2012 07:26
by gbeer7
Hi all,

Many thanks, all but works just need to add back in the date last modified then i'm good.

echo off
set flag=
for /f "skip=3 tokens=1-3,*" %%a IN ('dir *.mdb *.mde /a-d /tc /s') do (
if /i "%%d"=="bytes" set flag=1
if not defined flag if not "%%d"=="" (
echo File Name : "%%d"
echo File Extension : %%~xd
echo File Size : %%c
echo File Creation Date : %%a %%b
echo Fully Qualified Path : "%%~fd"
echo.
)
) >>all.txt
pause

Anyone help me with that please ?

Re: Batch file help

Posted: 28 Mar 2012 07:42
by Squashman
gbeer7 wrote:Hi all,

Many thanks, all but works just need to add back in the date last modified then i'm good.

Anyone help me with that please ?

You had it in your original code. What's the problem?

Re: Batch file help

Posted: 28 Mar 2012 07:51
by gbeer7
I wanted date created in there and date modified...if possible with the other bits.

Re: Batch file help

Posted: 28 Mar 2012 09:59
by foxidrive
Try this. It has one extra line.

Does this work with subdirectories? It is not designed to.

Code: Select all

echo off
set flag=
for /f "skip=3 tokens=1-3,*" %%a IN ('dir *.mdb *.mde /a-d /tc /s') do (
if /i "%%d"=="bytes" set flag=1
if not defined flag if not "%%d"=="" (
echo File Name            : "%%d"
echo File Extension       : %%~xd
echo File Size            : %%c
echo File Creation Date   : %%a %%b
echo Fully Qualified Path : "%%~fd"
ECHO Last-Modified Date : "%%~td"
echo.
)
)  >>all.txt
pause

Re: Batch file help

Posted: 28 Mar 2012 12:03
by Squashman
gbeer7 wrote:I wanted date created in there and date modified...if possible with the other bits.

I guess what I meant to say was you had the original code for the modified date in your original batch file. Was wondering what you didn't understand about using that original code in with the code you were given.

Re: Batch file help

Posted: 29 Mar 2012 00:54
by gbeer7
Brilliant, that works great !

set flag=
for /f "skip=3 tokens=1-3,*" %%a IN ('dir *.mdb *.mde /a-d /tc /s') do (
if /i "%%d"=="bytes" set flag=1
if not defined flag if not "%%d"=="" (
echo File Name : "%%d"
echo File Extension : %%~xd
echo File Size : %%c
echo File Creation Date : %%a %%b
echo Fully Qualified Path : "%%~fd"
ECHO Last-Modified Date : "%%~td"
echo.
)
) >>all.txt
pause



One final thing, how do i make it scan the sub directories ? Then i'm happy !!

Re: Batch file help

Posted: 29 Mar 2012 01:22
by foxidrive
Use another batch file to call the batch file which creates the list. (untested)


Code: Select all

@echo off
for /f "delims=" %%a in ('dir /ad /b /s') do (
pushd "%%a"
call "c:\bat\the batch file.bat"
popd
)

Re: Batch file help

Posted: 29 Mar 2012 01:39
by gbeer7
Thanks for your quick reply.

That didn't work, it just kept pushing out file not found.

Re: Batch file help

Posted: 29 Mar 2012 02:03
by foxidrive
Did you change "c:\bat\the batch file.bat" to point to your batch file?

Re: Batch file help

Posted: 29 Mar 2012 02:19
by gbeer7
Hi, yes i did. Found the file ok.

Re: Batch file help

Posted: 29 Mar 2012 04:23
by gbeer7
Hi, anyone able to help ? Need to do something for work and i'll be so grateful if anyone can help.