Batch file help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
gbeer7
Posts: 13
Joined: 28 Mar 2012 05:56

Batch file help

#1 Post by gbeer7 » 28 Mar 2012 06:00

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 ?

Squashman
Expert
Posts: 3664
Joined: 23 Dec 2011 13:59

Re: Batch file help

#2 Post by Squashman » 28 Mar 2012 06:25

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.

Squashman
Expert
Posts: 3664
Joined: 23 Dec 2011 13:59

Re: Batch file help

#3 Post by Squashman » 28 Mar 2012 06:47

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

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch file help

#4 Post by foxidrive » 28 Mar 2012 06:47

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

gbeer7
Posts: 13
Joined: 28 Mar 2012 05:56

Re: Batch file help

#5 Post by gbeer7 » 28 Mar 2012 07:26

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 ?

Squashman
Expert
Posts: 3664
Joined: 23 Dec 2011 13:59

Re: Batch file help

#6 Post by Squashman » 28 Mar 2012 07:42

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?

gbeer7
Posts: 13
Joined: 28 Mar 2012 05:56

Re: Batch file help

#7 Post by gbeer7 » 28 Mar 2012 07:51

I wanted date created in there and date modified...if possible with the other bits.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch file help

#8 Post by foxidrive » 28 Mar 2012 09:59

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

Squashman
Expert
Posts: 3664
Joined: 23 Dec 2011 13:59

Re: Batch file help

#9 Post by Squashman » 28 Mar 2012 12:03

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.

gbeer7
Posts: 13
Joined: 28 Mar 2012 05:56

Re: Batch file help

#10 Post by gbeer7 » 29 Mar 2012 00:54

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 !!

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch file help

#11 Post by foxidrive » 29 Mar 2012 01:22

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
)

gbeer7
Posts: 13
Joined: 28 Mar 2012 05:56

Re: Batch file help

#12 Post by gbeer7 » 29 Mar 2012 01:39

Thanks for your quick reply.

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

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: Batch file help

#13 Post by foxidrive » 29 Mar 2012 02:03

Did you change "c:\bat\the batch file.bat" to point to your batch file?

gbeer7
Posts: 13
Joined: 28 Mar 2012 05:56

Re: Batch file help

#14 Post by gbeer7 » 29 Mar 2012 02:19

Hi, yes i did. Found the file ok.

gbeer7
Posts: 13
Joined: 28 Mar 2012 05:56

Re: Batch file help

#15 Post by gbeer7 » 29 Mar 2012 04:23

Hi, anyone able to help ? Need to do something for work and i'll be so grateful if anyone can help.

Post Reply