#68369 - 2002-07-16 11:13 AM
Setting all files and directories to Hidden in a specific directory
|
kncowans
Getting the hang of it
Registered: 2000-11-11
Posts: 98
Loc: Doncaster, UK
|
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
_________________________
Kevin Cowans
Senior ICT Technician
The Armthorpe School
|
Top
|
|
|
|
#68371 - 2002-07-17 12:24 AM
Re: Setting all files and directories to Hidden in a specific directory
|
MCA
KiX Supporter
Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
|
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.
|
Top
|
|
|
|
#68374 - 2002-07-16 04:15 PM
Re: Setting all files and directories to Hidden in a specific directory
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
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)
|
Top
|
|
|
|
#68376 - 2002-07-16 04:22 PM
Re: Setting all files and directories to Hidden in a specific directory
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
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.
|
Top
|
|
|
|
#68378 - 2002-07-16 04:49 PM
Re: Setting all files and directories to Hidden in a specific directory
|
Radimus
Moderator
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
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.
|
Top
|
|
|
|
#68380 - 2002-07-17 09:56 PM
Re: Setting all files and directories to Hidden in a specific directory
|
kncowans
Getting the hang of it
Registered: 2000-11-11
Posts: 98
Loc: Doncaster, UK
|
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
_________________________
Kevin Cowans
Senior ICT Technician
The Armthorpe School
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 466 anonymous users online.
|
|
|