Page 1 of 1
Custom directory listing
Posted: 07 Jul 2009 08:42
by Marrone
What I have to do to make this code works?
Code: Select all
for /d %%d in (%APPDATA%\Mozilla\Firefox %LOCALAPPDATA%\Mozilla\Firefox) do (
if exist %%d (
for /r %%f in (%%d\*.sqlite) do (
set name=%%~nf .
set name=!name:~0,14!
set size=%%~zf
echo.!name! !size!
)
)
)
Thanks anyway.
PS: I DON'T WANT VBScript.
Posted: 07 Jul 2009 09:24
by RElliott63
Marrone,
What's the error you're receiving? If the %AppData% or %LocalAppData% have spaces in it, then you won't get the whole path presented in %%d, thus not finding the actual folder you're looking for.
You might want to use quotes and remove them with %%~D as needed.
-Rick
Posted: 07 Jul 2009 14:03
by Marrone
Rick,
The environment variables actually works, but I'll quote them to avoid unintentional problems. Thanks for this tip.
The problem I'm giving is that the nested
for doesn't working, even that it's apparently Ok. The
if statement passes, but the nested
for doesn't iterate over.
Thanks anyway.
![Smile :)](./images/smilies/icon_smile.gif)
Posted: 07 Jul 2009 23:59
by RElliott63
OK, try this... it should help you get somewhere with it...
Code: Select all
@Echo Off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
for /d %%d in (%APPDATA%\Mozilla\Firefox %LOCALAPPDATA%\Mozilla\Firefox) do (
if exist %%d\*.sqlite (
for /f %%f in ('Dir /b %%d\*.sqlite') do (
set name=%%~nf .
set name=!name:~0,14!
set size=%%~zf
echo.!name! !size!
)
) Else (Echo Files do not exist!)
)
Posted: 08 Jul 2009 11:17
by avery_larry
I believe Relliott got it right -- the spaces in %appdata% and/or %localappdata% are causing problems -- unless you don't have spaces in those paths. Add to that the fact that you can't use quotes inside the basic for loops and you'll be stuck. Try this:
Code: Select all
@Echo Off
for %%d in ("%APPDATA%\Mozilla\Firefox" "%LOCALAPPDATA%\Mozilla\Firefox") do (
if exist %%d (
for /f "usebackq tokens=* delims=" %%f in (`dir /b /s "%%~d\*.sqlite"`) do (
echo.%%~nf %%~zf
)
) Else (
Echo %%d does not exist!
)
)
Though I don't quite understand the purpose of the else statement--since you apparently want to search the subfolders for *.sqlite . . .