helpmeh... all your code does is emulate the /s switch.
attrib has a /s switch, btw, so attrib *.* -a /s would accomplish the same thing.
however, the main issue here is that it will refuse to change the attributes on hidden or system files.
you could do:
attrib *.* -s -h -a /s
but this has another problem since we don't want to permanently remove the hidden and system attributes, bringing us back to the iterative loop idea.
Anyway, to cut a long story short I spent at least an hour trying to make a batch solution. Gave up, and then wrote a VBScript in about 5 minutes
Dim FSO
Dim usefolder
set FSO = CreateObject("Scripting.FileSystemObject")
set usefolder= FSO.GetFolder(CreateObject("WScript.Shell").CurrentDirectory)
'WScript.Echo usefolder.name
Removearchiveattrib usefolder
Sub RemoveArchiveAttrib(InFolder)
Dim CurrFile,CurrFolder
For Each CurrFile in InFolder.Files
if (Currfile.Attributes And 32)=32 then
'has the archive attribute, remove it.
currfile.attributes = currfile.attributes-32
'WScript.echo "archive attribute found on file:" & currfile.name
end if
Next
for each Currfolder in InFolder.SubFolders
RemoveArchiveAttrib Currfolder
Next
End Sub
I tested this, and it works great for me
To use it simply paste it into notepad, and then save it as a "VBS" file- preferably in the folder you wish to work with, or, even better a test folder to see if it works. then you should be able to double-click it to run it.
for the record, the batch code that I had (which failed to work at all) was this:
SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims==*" %%i in ('dir /s /b /a') do (
echo working on "%%i"
attrib "%%i" | findstr "^A H "
if not errorlevel 1 (
echo file is hidden but not system %%i
)
attrib "%%i" | findstr "^A S "
if not errorlevel 1 (
echo file is system, but not hidden %%i
)
attrib "%%i" | findstr "^A SH "
if not errorlevel 1 (
echo file is system and hidden %%i
)
)
attrib %0.bat -h -s
there were attrib commands in each block which basically removed the attribute it discovered, removed the archive attribute, and then set back the original attributes. problem was the last test for system AND hidden was always true so it would end up with both System and hidden regardless of the original attributes. It wouldn't ahve the archive attribute anymore, though. So At least there was that.