View unanswered posts | View active topics It is currently 30 Oct 2014 06:56



Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next
Batch file help 
Author Message

Joined: 28 Mar 2012 05:56
Posts: 13
Post Batch file help
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 ?


28 Mar 2012 06:00
Profile

Joined: 23 Dec 2011 13:59
Posts: 1950
Post Re: Batch file help
Code:
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.


28 Mar 2012 06:25
Profile

Joined: 23 Dec 2011 13:59
Posts: 1950
Post Re: Batch file help
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:
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


28 Mar 2012 06:47
Profile

Joined: 10 Feb 2012 02:20
Posts: 4324
Post Re: Batch file help
This works in XP with 24 hour time.

Code:
@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


28 Mar 2012 06:47
Profile

Joined: 28 Mar 2012 05:56
Posts: 13
Post Re: Batch file help
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 ?


28 Mar 2012 07:26
Profile

Joined: 23 Dec 2011 13:59
Posts: 1950
Post Re: Batch file help
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?


28 Mar 2012 07:42
Profile

Joined: 28 Mar 2012 05:56
Posts: 13
Post Re: Batch file help
I wanted date created in there and date modified...if possible with the other bits.


28 Mar 2012 07:51
Profile

Joined: 10 Feb 2012 02:20
Posts: 4324
Post Re: Batch file help
Try this. It has one extra line.

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

Code:
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


28 Mar 2012 09:59
Profile

Joined: 23 Dec 2011 13:59
Posts: 1950
Post Re: Batch file help
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.


28 Mar 2012 12:03
Profile

Joined: 28 Mar 2012 05:56
Posts: 13
Post Re: Batch file help
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 !!


29 Mar 2012 00:54
Profile

Joined: 10 Feb 2012 02:20
Posts: 4324
Post Re: Batch file help
Use another batch file to call the batch file which creates the list. (untested)


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


29 Mar 2012 01:22
Profile

Joined: 28 Mar 2012 05:56
Posts: 13
Post Re: Batch file help
Thanks for your quick reply.

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


29 Mar 2012 01:39
Profile

Joined: 10 Feb 2012 02:20
Posts: 4324
Post Re: Batch file help
Did you change "c:\bat\the batch file.bat" to point to your batch file?


29 Mar 2012 02:03
Profile

Joined: 28 Mar 2012 05:56
Posts: 13
Post Re: Batch file help
Hi, yes i did. Found the file ok.


29 Mar 2012 02:19
Profile

Joined: 28 Mar 2012 05:56
Posts: 13
Post Re: Batch file help
Hi, anyone able to help ? Need to do something for work and i'll be so grateful if anyone can help.


29 Mar 2012 04:23
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 30 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.