Batch file help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file help

#16 Post by foxidrive » 29 Mar 2012 07:44

What problem do you still have? You said it finds the file.

If it is still returning 'File not found' then some directories may not have any *.mdb *.mde files in them. It should still process the ones where it does have those file types.

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

Re: Batch file help

#17 Post by gbeer7 » 29 Mar 2012 07:56

Hi, the problem i'm having is i want the batch file to scan sub-directories.

The rest is fine...

Echo off
set flag=
for /f "skip=3 tokens=1-3,*" %%a IN ('dir *.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 Last-Modified Date : "%%~td"
)
) >>all.txt
pause
Last edited by gbeer7 on 29 Mar 2012 08:00, edited 1 time in total.

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

Re: Batch file help

#18 Post by foxidrive » 29 Mar 2012 08:08

I'm sorry but I can't help unless you tell me what YOU see when running the batch files.

One batch file is for scanning a folder. You say it works.
The other batch file will use it to scan each folder in a subdirectory tree.

Please post the second batch file you are using too.

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

Re: Batch file help

#19 Post by gbeer7 » 29 Mar 2012 08:17

OK the details i see from the above script is what i want, but I want it to scan sub-directories not just the local path. Does that makes sense ?

I was using second batch someone supplied on this post, but it doesn't work, doesn't scan the folders for *.mde and *.mdb.

basically it just keeps pushing out file not found all done the screen and never stops. It is seeing the 2nd batch file.

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

Re: Batch file help

#20 Post by foxidrive » 29 Mar 2012 08:22

I supplied that second batch file too. It should work...

Post that 2nd batch file that you are using too please.

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

Re: Batch file help

#21 Post by foxidrive » 29 Mar 2012 09:33

Sorry matey but you are doing something wrong. The 2nd batch file works fine.

If you don't post both the batch files that you are using then we can't help, because we can't see your computer and what you are doing.

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

Re: Batch file help

#22 Post by gbeer7 » 30 Mar 2012 00:43

Hi,

here is script one,

@echo off
for /f "delims=" %%a in ('dir /ad/b/s') do (
pushd "%%a"
call "E:\UserData\second.bat"
popd
)

Which then calls script two,

Echo off
set flag=
for /f "skip=3 tokens=1-3,*" %%a IN ('dir *.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 Last-Modified Date : "%%~td"
echo.
)
) >>all.txt

It just pumps "file cannot be found" , I let it run through for a while and it didnt find any *mdb or *mde files and i know for sure there are some in the directories its looking.

Thank you for you time on this. :)
Last edited by gbeer7 on 30 Mar 2012 01:31, edited 1 time in total.

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

Re: Batch file help

#23 Post by foxidrive » 30 Mar 2012 07:42

gbeer7 wrote:Hi,

here is script one,

@echo off
for /f "delims=" %%a in ('dir /ad/b/s') do (
pushd "%%a"
call "E:\UserData\second.bat"
popd
)

Which then calls script two,

@Echo off
set flag=
echo "%cd%"
for /f "skip=3 tokens=1-3,*" %%a IN ('dir *.mdb *.mde /a-d /tc 2^>nul ') 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.
)
) >>c:\all.txt

It just pumps "file cannot be found" , I let it run through for a while and it didnt find any *mdb or *mde files and i know for sure there are some in the directories its looking.

Thank you for you time on this. :)


Make the changes above and try it.

You will find "all.txt" files in all the folders you ran it on with *.mdb *.mde files, when you were testing it.

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

Re: Batch file help

#24 Post by gbeer7 » 30 Mar 2012 07:59

Thank you.

Just run that, its now displaying this :-

File Name : "Stuff\Leavers"
File Extension :
File Size : E:\UserData\*\*\*
File Creation Date : Directory of
Fully Qualified Path : "E:\UserData\*\*\*\*\*\*"
Last-Modified Date : ""

I've added * to blank out the folder names. So its not putting the MDB or MDE file name, File extension, size, creation and last modifiled.

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

Re: Batch file help

#25 Post by foxidrive » 30 Mar 2012 08:05

Is this in c:\all.txt ?

I didn't change the logic at all - the second.bat file doesn't seem to be working for the files.

Can you run second.bat itself in a folder with *.mdb *.mde files?

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

Re: Batch file help

#26 Post by foxidrive » 30 Mar 2012 08:11

Try this as second.bat

Code: Select all

@Echo off
set flag=
echo "%cd%"
for /f "skip=2 tokens=1-3,*" %%a IN ('dir *.mdb *.mde /a-d /tc 2^>nul ^|find /v /i " Directory of "') 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.
)
) >>c:\all.txt

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

Re: Batch file help

#27 Post by foxidrive » 30 Mar 2012 08:24

Here is a single batch file version. The logic is changed in the subroutine to simplify the exercise. It still requires 24 hour time to use the right tokens.

Code: Select all

@echo off
for /f "delims=" %%a in ('dir /ad /s /b') do call :subroutine "%%a"
pause
goto :EOF

:subroutine
pushd "%~1"
set flag=
echo "%cd%"
for /f "tokens=1-3,*" %%a IN ('dir *.mdb *.mde /a-d /tc 2^>nul ^|find ":" ^|find /v /i " Directory of "') do (
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.
) >>c:\all.txt
popd

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

Re: Batch file help

#28 Post by gbeer7 » 30 Mar 2012 08:45

Hi, just running the all-in-one now. I appricate you taking the time with this.

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

Re: Batch file help

#29 Post by gbeer7 » 30 Mar 2012 08:50

Amazing, thank you ! it works a treat. Thanks for you time and effort, very kind.

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

Re: Batch file help

#30 Post by foxidrive » 30 Mar 2012 09:28

That's good, and you're welcome.

Post Reply