DosTips.com

A Forum all about DOS Batch
It is currently 27 May 2016 06:15

All times are UTC-06:00




Post new topic  Reply to topic  [ 30 posts ]  Go to page 1 2 Next
Author Message
 Post subject: Batch file help
PostPosted: 28 Mar 2012 06:00 
Offline

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


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 06:25 
Offline

Joined: 23 Dec 2011 13:59
Posts: 3056
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.


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 06:47 
Offline

Joined: 23 Dec 2011 13:59
Posts: 3056
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


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 06:47 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5595
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


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 07:26 
Offline

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


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 07:42 
Offline

Joined: 23 Dec 2011 13:59
Posts: 3056
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?


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 07:51 
Offline

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


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 09:59 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5595
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


Top
   
 Post subject: Re: Batch file help
PostPosted: 28 Mar 2012 12:03 
Offline

Joined: 23 Dec 2011 13:59
Posts: 3056
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.


Top
   
 Post subject: Re: Batch file help
PostPosted: 29 Mar 2012 00:54 
Offline

Joined: 28 Mar 2012 05:56
Posts: 13
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 !!


Top
   
 Post subject: Re: Batch file help
PostPosted: 29 Mar 2012 01:22 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5595
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
)


Top
   
 Post subject: Re: Batch file help
PostPosted: 29 Mar 2012 01:39 
Offline

Joined: 28 Mar 2012 05:56
Posts: 13
Thanks for your quick reply.

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


Top
   
 Post subject: Re: Batch file help
PostPosted: 29 Mar 2012 02:03 
Offline

Joined: 10 Feb 2012 02:20
Posts: 5595
Did you change "c:\bat\the batch file.bat" to point to your batch file?


Top
   
 Post subject: Re: Batch file help
PostPosted: 29 Mar 2012 02:19 
Offline

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


Top
   
 Post subject: Re: Batch file help
PostPosted: 29 Mar 2012 04:23 
Offline

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


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 30 posts ]  Go to page 1 2 Next

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 10 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® Forum Software © phpBB Limited