counting Files

Microsoft Windows xp home edition
January 30, 2010 at 00:23:31
Specs: Windows XP, AMD Sempron 2000
Hi all,

I run a jukebox program on my pc and use a file called update.bat to update its database from a single music folder.

I have a bat file that will count the contents of the music folder, and I'm looking for a solution that will 'call' a second file,

for example,

if there are new files, continue deleting database files and run update.exe

if not, then start jukebox program without deleting files or running update.exe

Many thanks


See More: counting Files

Report •

#1
January 30, 2010 at 05:14:58
@echo off & setLocal EnableDELAYedeXpansion

if not exist %TEMP%\prev dir/b/a-d > %TEMP%\prev
dir/b/a-d > %TEMP%\new

fc %TEMP%\prev %TEMP%\new > nul

goto :!errorlevel!

:1
echo changes : do the database thing
dir/b/a-d > %TEMP%\prev
goto :eof

:0
echo no changes


=====================================
Helping others achieve escape felicity

M2


Report •

#2
January 31, 2010 at 23:11:56
M2Go, many thanks for your quick reply,

Hopefully I will be able to use the above to run my script, however i don't understand what to do next...this is what I have so far...

I have this placed in the folder where all the media is stored for jukebox...

*counter.txt'

@ECHO Checking For New Folders, Please Wait...
@ECHO This May Take Several Minutes Depending On The Amount Of Files...
@ECHO OFF

del "H:\Jukebox\Music\counter.txt"/Q /S >nul
setlocal enabledelayedexpansion
set folder=H:\Jukebox\Music
for /f "tokens=* delims=" %%v in ('dir /b "%folder%"') do (
for /f "tokens=* delims=" %%i in ('dir /a:-d /b "%%v" 2^>^&1') do (
if /i %%i NEQ "File Not Found" call set /a count=%%count+1
)
echo %%~nv: !count! >> counter.txt
set count=0
)
EXIT

This runs and populates the folder's contents, then outputs the results as 'counter.txt'. This would be ran to create the FIRST EVER counter.txt that the rest of the processes will depend on...

The next file would first delete the old 'counter_old.txt' and rename the 'counter.txt' to 'counter_old.txt' then create a 'new counter.txt' file to compare to...

*counter with Del and ren.txt*

ECHO Checking For New Folders, Please Wait...
@ECHO This May Take Several Minutes Depending On The Amount Of Files...
@ECHO OFF
del "h:\Jukebox\Music\counterold.txt"/Q /S >nul
ren h:\Jukebox\Music\counter.txt counterold.txt
setlocal enabledelayedexpansion
set folder=H:\Jukebox\Music
for /f "tokens=* delims=" %%v in ('dir /b "%folder%"') do (
for /f "tokens=* delims=" %%i in ('dir /a:-d /b "%%v" 2^>^&1') do (
if /i %%i NEQ "File Not Found" call set /a count=%%count+1
)
echo %%~nv: !count! >> counter.txt
set count=0
)
EXIT

The next one is the 'update.bat I will use IF there are new files in the folder...

*update.bat'
@ECHO Checking for updates and Loading Freebox...Please Wait...
@ECHO OFF

begin batch file:

del "C:\Program Files\E-Touch Jukebox\records.bak"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\records.cvr"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\records.rec"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\records.rex"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\Artist"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\Genres"/Q /S >nul
START /d "C:\Program Files\E-Touch Jukebox" Config4.exe /DRIVE h:\Jukebox\Music /GENRE /ARTIST /LAUNCH /NEW records
EXIT

The above deletes the database files the jukebox uses to hold tracks and then runs a utility to recreate the database fies from the media folder...

What i need now is the knowhow to put this all together in the following way...

1. Run 'Counter.bat'

2. Run 'Counter with del and ren.bat'

3. Compare counter.txt to 'counter_old.txt,
run 'update.bat' if there are any changes, ie New Files, or exit and run 'c:\program files\e-touch jukbox\e-touch5.exe' if there are no changes...

If somebody could use the 3 files i've posted here and put them into the response fro Mechanix2go, i will be over the moon!


Report •

#3
February 1, 2010 at 13:48:54
hello: it looks like you're going through a whole lot of hoops you don't need to, and prob'ly won't get results you wanted.
I'm not sure how the first section (to count files) could work. it looks like it reads each filename from the directory and then does a "dir" on that filename looking for "file not found", which should never happen!
M2's code does what you want, maybe you're just unsure how to implement it. If you need the filecount (as opposed to just seeing if the dir. has changed):

for /f %%a in ('dir /b /a-d ^| find /i /v /c ""') do set cnt=%%a

will put the filecount into %cnt% but with M2's code you don't need that. maybe this can help (his code with your stuff):

@echo off & setLocal EnableDELAYedeXpansion

if not exist %TEMP%\prev dir/b/a-d > %TEMP%\prev
dir/b/a-d > %TEMP%\new

fc %TEMP%\prev %TEMP%\new > nul

goto :!errorlevel!

:1
echo changes : do the database thing
call update.bat
dir/b/a-d > %TEMP%\prev
goto :eof

:0
echo no changes
c:\program files\e-touch jukbox\e-touch5.exe
:--------------------------- snip - end of main

in UPDATE.BAT, be SURE to remove the EXIT at the end (so it can come back to main to refresh the directory) and you might want to change last line, i think (not real sure though):
START /d "C:\Program Files\E-Touch Jukebox\Config4.exe" /DRIVE h:\Jukebox\Music /GENRE /ARTIST /LAUNCH /NEW records
:::::::::::EXIT take this out!


Report •

Related Solutions

#4
February 1, 2010 at 22:50:20
Thanks for the reply...

What I'm looking for is a way to check the 'Music' folder against a list of folders that was populated using a similar procedure to the 'count' I used. I suppose it's the MUSIC folder's size that will ultimately change, so I could compare 2 logs of the file size writtten the same way as 'count.bat'...

I want it to run Update.bat if there 'are' new files, or Run c:\program files\e-touch jukbox\e-touch5.exe if there 'aren't'.

The thing is, I'm a complete novice with batch files so I don't understand what Im doing completely...i have recycled .bat files created by other jukebox users and modified them according to my system structure...

The Line "START /d "C:\Program Files\E-Touch Jukebox\Config4.exe" /DRIVE h:\Jukebox\Music /GENRE /ARTIST /LAUNCH /NEW records" is the most important line of update.bat - it is basically the 'settings' for the config program that is used to build the database, ie Start the program using H:\Jukebox\Music and build GENRE and ARTIST databases and then new records database...I agree the exit part needs to go...many thanks for your help, I hope i've explained clearly enough for you to assist me a bit more...


Report •

#5
February 1, 2010 at 23:31:07
i guess i'm officially "confused" (as usual!)
"What I'm looking for is a way to check the 'Music' folder against a list of folders that was populated using a similar procedure to the 'count' I used. I suppose it's the MUSIC folder's size that will ultimately change, so I could compare 2 logs of the file size writtten the same way as 'count.bat'..."

one interpretation: has the main (Music) folder changed (no. of files, reflected in diff of old_count vs new_count txt)
two interp: is the main Music folder synch with all the subfolders of the jukebox app, which doesn't seem to be the case but i might be wrong. they all get deleted whenever the primary (Music) folder changes anyway, it looks like.
interp #1 is fairly easy, and M2's work does that.

interp #2, well, waiting for the other shoe to drop.

the update.bat should be fine as you have it now.


Report •

#6
February 4, 2010 at 05:56:38
I've actually managed to sort it now...used 3 batch files and ran them in sequence...

Start file counter.bat....copy everything below this line until exit..

@ECHO Counting Folders, Please Wait...
@ECHO OFF
@ECHO Deleting 'prev.txt'...
@ECHO Renaming 'new.txt' To 'prev.txt'...
@ECHO Creating New Version Of 'new.txt'...
@ECHO Checking For New Folders, Please Wait...
@ECHO This May Take Several Minutes Depending On The Amount Of Files...
@ECHO OFF
if not exist h:\jukebox\Music\new.txt dir/b/a-d > h:\jukebox\Music\\prev.txt
dir/b/a-d > h:\jukebox\Music\\new.txt
del "h:\Jukebox\Music\prev.txt"/Q /S >nul
ren h:\Jukebox\Music\new.txt prev.txt
setlocal enabledelayedexpansion
set folder=H:\Jukebox\Music
for /f "tokens=* delims=" %%v in ('dir /b "%folder%"') do (
for /f "tokens=* delims=" %%i in ('dir /a:-d /b "%%v" 2^>^&1') do (
if /i %%i NEQ "File Not Found" call set /a count=%%count+1
)
echo %%~nv: !count! >> new.txt
set count=0
)
del "h:\Jukebox\Music\prev.txt"/Q /S >nul
ren h:\Jukebox\Music\new.txt prev.txt
setlocal enabledelayedexpansion
set folder=H:\Jukebox\Music
for /f "tokens=* delims=" %%v in ('dir /b "%folder%"') do (
for /f "tokens=* delims=" %%i in ('dir /a:-d /b "%%v" 2^>^&1') do (
if /i %%i NEQ "File Not Found" call set /a count=%%count+1
)
echo %%~nv: !count! >> new.txt
set count=0
)
call "h:\jukebox\music\checker.bat"
EXIT

Start file checker.bat...copy everything below this line until exit.

@echo off & setLocal EnableDELAYedeXpansion

FC /b h:\jukebox\music\new.txt h:\jukebox\music\prev.txt

goto :!errorlevel!

:1
@echo Changes : Updating Database...
call "h:\jukebox\music\update.bat"
dir/b/a-d > changes.txt
goto :eof

:0
echo no changes
START /d "C:\Program Files\E-Touch Jukebox" etouch5.exe
exit

Star update.bat...copy everything below this line until exit.

del "C:\Program Files\E-Touch Jukebox\records.bak"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\records.cvr"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\records.rec"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\records.rex"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\Artist"/Q /S >nul
del "C:\Program Files\E-Touch Jukebox\Genres"/Q /S >nul
START /d "C:\Program Files\E-Touch Jukebox" Config4.exe /DRIVE H:\Jukebox\Music /GENRE /ARTIST /LAUNCH /NEW records
EXIT

Cheers for all your help!


Report •

Ask Question