For loop over hidden files

Dell Precision m65 notebook
February 6, 2010 at 21:16:45
Specs: Windows XP
Hi,

I was trying to write a for loop to recursively go over all the files in a specified directory:

FOR /R %1 %%i in (*) do call batch.bat %%i

My only problem is that it ignores hidden files.
Any clues on how to include hidden files?

Thanks
~Steve


**Edit

After some searching I found a way to display the names:

DIR /A/OGN

That doesn't exactly help me though as the batch I call in the for loop doesn't see the file when I pass it the name on its own.


See More: For loop over hidden files

Report •

#1
February 7, 2010 at 05:20:21
Without knowing anything about the called bat, I'd say just unhide them.


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

M2


Report •

#2
February 7, 2010 at 05:59:44
It's an interesting question ... I think you have to use /F instead of /R, basically to allow a command to be used. The problem with the "set" is that it is meant for standard behaviour, which is not what you want. I came to this :

for /F %%f in ('dir *.* /B /S /AH') do echo %%f

It does look for files in subdirs, and it does show the hidden ones ... but the problem is then this : it only shows the hidden ones. So, you would have to run this as well (for the non-hidden files) :

for /F %%f in ('dir *.* /B /S /A-H') do echo %%f

which should be the same as:

for /F %%f in ('dir *.* /B /S') do echo %%f

It also shows the full path, so no issue with file not being found cause you run it from different path or so.


Report •

#3
February 7, 2010 at 06:03:02
> Without knowing anything about the called bat,
> I'd say just unhide them.
>

Are you being sarcastic here, M2 ?


Report •

Related Solutions

#4
February 7, 2010 at 09:18:40
Well,

I'll supply a little more information-

In essence I am trying to build a graph of what file types are stored on a particular computer. This is just a helper that is passing names to TrID.exe (http://mark0.net/soft-trid-e.html).

TrID is analyzing the binary format of the files and returning the best match. (It might seem like overkill but its what I'm trying to do.)

The third line doesn't search both.
for /F %%f in ('dir *.* /B /S') do echo %%f

I've got a working version by running both searches - but as I am scanning the entire HD I would love if someone could do it in one loop.


Report •

#5
February 7, 2010 at 19:42:03
try using attrib instead of dir. You DO have to adjust the substring, but it does have added benefit if you need to unhide the files as M2 suggested (& you can re-hide them if necessary):
(not tested)

setlocal enabledelayedexpansion
for /f "tokens=* delims=" %%a in ('attrib /s *.*') do (
set xx=%%a
: S, system file attribute or space if not
set ss=!xx:~3,1!
: H, hidden file attribute or space if not
set hh=!xx:~4,1!
:filename, long format requiring quotes around it
set xx=!xx:~11!
:this only needs done if you need to unhide the files:
attrib -!ss! !xx! >nul
attrib -!hh! !xx! >nul
call batch.bat "!xx!"
:this only needs done if you need to rehide the files:
attrib +!ss! !xx! >nul
attrib +!hh! !xx! >nul
)




Report •

#6
February 8, 2010 at 04:50:59
> The third line doesn't search both.
> for /F %%f in ('dir *.* /B /S') do echo %%f
>
> I've got a working version by running both searches -
> but as I am scanning
> the entire HD I would love if someone could do it in one
> loop.
>

Hmmyeah, it would made sense you could do a DIR search on both with and without, but it indeeds seems to be like that ... a bit silly if it is like that. Something we have to live with I guess ...

PS, I would like to disadvise usage of ATTRIB here, unless you want to risk losing/adding attributes of/to files.


Report •

#7
February 9, 2010 at 04:16:37
@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('attrib /s d:\*.*') do (
set F=%%a
set F=!F:~11!
echo !F!
)


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

M2


Report •

#8
February 10, 2010 at 03:02:40
Hi Buddy!!!

Thanks for sharing you skill about programming.. meet again.


Report •

#9
February 10, 2010 at 05:33:33
That's much better M2 ... Response 1 was - excuse me for saying - a crap response ... Response 7 is right on.

Only the fact you have to abuse the ATTRIB command, while the DIR command should be able to do it, but that is not your fault.


Report •

#10
February 10, 2010 at 20:32:35
Thanks!

Much appreciation :)


Report •

Ask Question