kncowans
|
(Getting the hang of it)
|
2002-07-16 11:13 AM
|
|
|
|
|
Setting all files and directories to Hidden in a specific directory
|
|
Hello all
Could someone please look over the following script and tell me why the following script will not always set the files and directories to Hidden in the specified folder.
code:
Del "%WinDir%\Temp.dat" Del "%WinDir%\Temp2.dat"
$tempfile = "%WinDir%\temp.dat" $tempfile2 = "%WinDir%\temp2.dat"
Dim $tempdir_data[99999]
Shell "%ComSpec% /c dir N:\ /a-h /b > $tempfile" Shell "%ComSpec% /c dir N:\ /ad-h /b > $tempfile2"
$Temp = Open(1,$tempfile) $Temp2 = Open(2,$tempfile2) $tempfile_data = ReadLine(1) $tempfile2_data = ReadLine(2) While @error = 0 SetFileAttr("N:\$tempfile_data" , 2)
$tempfile_data = ReadLine(1)
Loop While @error = 0 SetFileAttr("N:\$tempfile2_data" , 2)
$tempfile_data = ReadLine(2)
Loop SetFileAttr("N:\Files" , 128)
$Temp = Close(1) $Temp2 = Close(2)
Del $tempfile Del $tempfile2
Thanks in advance
|
Lonkero
|
(KiX Master Guru)
|
2002-07-17 12:11 AM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
first: Del "%WinDir%\Temp.dat" Del "%WinDir%\Temp2.dat" $tempfile = "%WinDir%\temp.dat" $tempfile2 = "%WinDir%\temp2.dat" is long way. try it with: $tempfile = "%WinDir%\temp.dat" $tempfile2 = "%WinDir%\temp2.dat" Del $tempfile Del $tempfile2
then: Dim $tempdir_data[99999]
why you use an array if you don't actually use it? and are you sure there is no possibility that it goes over 100.000
also, you do separately two listings when you could do both at the same time. by adding the last one to the end of first listing: Shell "%ComSpec% /c dir N:\ /a-h /b > $tempfile "Shell "%ComSpec% /c dir N:\ /ad-h /b >> $tempfile"
also, when you use ">" it destroys the old stuff in it so you dont have to del it. so the start can be just: $tempfile = "%WinDir%\temp.dat" Shell "%ComSpec% /c dir N:\ /a-h /b > $tempfile "Shell "%ComSpec% /c dir N:\ /ad-h /b >> $tempfile"
then your problem probably is that you do the loops: while not @error ... loop while not @error ;<-does not execute as while has exited with error. ... loop
it's just probably.
if you do it with this script, what is the outcome:
code:
$tempfile = "%WinDir%\temp.dat" Shell "%ComSpec% /c dir N:\ /a-h /b > $tempfile" Shell "%ComSpec% /c dir N:\ /ad-h /b >> $tempfile" $Temp = Open(1,$tempfile) $tempfile_data = ReadLine(1)
While @error = 0 SetFileAttr("N:\$tempfile_data" , 2) $tempfile_data = ReadLine(1) Loop
SetFileAttr("N:\Files" , 128) $Temp = Close(1) $Temp2 = Close(2) Del $tempfile
cheers,
|
MCA
|
(KiX Supporter)
|
2002-07-17 12:24 AM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
Dear,
First some remarks:
- it is not necessary to delete the temporary files first, when you
are redirecting the output in the way you are doing. - DIM statement isn't necessary
- to prevent unexpected results. use the OPEN status for doing
READLINEs on that file. - shows an error status when you are doing a SetFileAttr call.
code:
IF SetFileAttr("n:\$tempfile_data", 2) ? "Warning KIX-SET2: '$tempfile_data' error @error (@serror)" ENDIF
- your line $tempfile_data = ReadLine(2) should be
$tempfile2_data = ReadLine(2) What is possible that you can't change attributes is: file is in use. To verify that, we have add the GetFileTime function.
Try our version any report possible problem to the board.
code:
$tempfile = "%WinDir%\temp.dat" $tempfile2 = "%WinDir%\temp2.dat"
SHELL "%comspec% /c dir N:\ /a-h /b >$tempfile" SHELL "%comspec% /c dir N:\ /ad-h /b >$tempfile2"
IF (Open(1,$tempfile) = 0) $tempfile_data=ReadLine(1) WHILE @error = 0 IF SetFileAttr("n:\$tempfile_data", 2) ? "Warning KIX-SET: '$tempfile_data' "+GetFileTime($tempfile_data)+" error @error (@serror)" ENDIF $tempfile_data=ReadLine(1) LOOP IF Close(1) ENDIF ENDIF IF (Open(2,$tempfile2) = 0) $tempfile2_data=ReadLine(2) WHILE @error = 0 IF SetFileAttr("n:\$tempfile2_data", 2) ? "Warning KIX-SET2: '$tempfile2_data' "+GetFileTime($tempfile2_data)+" error @error (@serror)" ENDIF $tempfile2_data=ReadLine(2) LOOP IF Close(2) ENDIF ENDIF ; IF SetFileAttr("n:\files", 128) ? "Warning KIX: 'n:\files' error @error (@serror)" ENDIF ; DEL $tempfile DEL $tempfile2
greetings.
|
Lonkero
|
(KiX Master Guru)
|
2002-07-16 01:03 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
heh. mca, seems that we are concerned with a little bit different manners.
same was: -deletion not needed -dim (array) not needed
differences: -error status display on set (MCA) -execute only if open succesful (MCA) -code minimized (Lonkero)
kncowans, if you compine these two methods you get a robust script which tells you if something isn't going as expected.
cheers,
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
Might be a permissions problem if the HIDDEN property is not being set. An ?''+@ERROR+' - '+@SERROR after the SETFILEATTRIB will tell you why it doesn't do something.
|
Radimus
|
(KiX Supporter)
|
2002-07-16 04:15 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
what about this???
code:
break on
$dir="c:\temp"
$d=dir("$dir") while @error=0 if not (getfileattr("$dir\$d") & 2) $=setfileattr("$dir\$d", 2) ? $d " is now hidden" endif $d=dir() loop $=setfileattr("$dir", 128)
|
Lonkero
|
(KiX Master Guru)
|
2002-07-16 04:17 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
rad, you got best golf score! good for you
|
Radimus
|
(KiX Supporter)
|
2002-07-16 04:22 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
version 2
code:
break on
$dir="c:\temp"
$d=dir("$dir") while @error=0 $=setfileattr("$dir\$d", 2) ? $d " is now hidden" $d=dir() loop $=setfileattr("$dir", 128)
dir() will not return hidden files anyway, so the IF isn't necessary.
|
Lonkero
|
(KiX Master Guru)
|
2002-07-16 04:40 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
now I beat you. crash to the mud, heh....
this is the shortest one for now:
code:
break on $dir="c:\temp" $d=dir("$dir") while 0=setfileattr("$dir\$d", 2) ? $d " is now hidden" $d=dir() loop $=setfileattr("$dir", 128)
I would still like to use it without the break on and without $dir variable (little shorter) but this is good enough...
so the shortest would be:
code:
$d="c:\temp" $f=dir("$dir") while 0=setfileattr("$d\$f",2) ? $f " is now hidden" $f=dir() loop $=setfileattr("$d", 128)
cheers, [ 16 July 2002, 16:43: Message edited by: Lonkero ]
|
Radimus
|
(KiX Supporter)
|
2002-07-16 04:49 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
but now it will error out and stop if the setfileattr fails... perhaps a file lock or permission issue, then the rest of the files will not be processed.
|
Lonkero
|
(KiX Master Guru)
|
2002-07-16 04:54 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
yeah... so, I go for just little shorter which does same thing with real world not ideal.
code:
$d="c:\temp" $f=dir("$dir") do $=setfileattr("$d\$f",2) ? $f " is now hidden" $f=dir() until @error $=setfileattr("$d", 128)
cheers, [ 16 July 2002, 16:54: Message edited by: Lonkero ]
|
kncowans
|
(Getting the hang of it)
|
2002-07-17 09:56 PM
|
|
|
|
|
Re: Setting all files and directories to Hidden in a specific directory
|
|
Hello all
Thanks for everyones help with this one.
I originally found the script on one of the scripting sites and left it in its original state.
Bye for now
Kevin
|