Page 1 of 1 1
Topic Options
#68369 - 2002-07-16 11:13 AM Setting all files and directories to Hidden in a specific directory
kncowans Offline
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
#68370 - 2002-07-17 12:11 AM Re: Setting all files and directories to Hidden in a specific directory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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 [Big Grin]

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,
_________________________
!

download KiXnet

Top
#68371 - 2002-07-17 12:24 AM Re: Setting all files and directories to Hidden in a specific directory
MCA Offline
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.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#68372 - 2002-07-16 01:03 PM Re: Setting all files and directories to Hidden in a specific directory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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,
_________________________
!

download KiXnet

Top
#68373 - 2002-07-16 03:52 PM Re: Setting all files and directories to Hidden in a specific directory
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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.
_________________________
There are two types of vessels, submarines and targets.

Top
#68374 - 2002-07-16 04:15 PM Re: Setting all files and directories to Hidden in a specific directory
Radimus Moderator Offline
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)

_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#68375 - 2002-07-16 04:17 PM Re: Setting all files and directories to Hidden in a specific directory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
rad, you got best golf score!
good for you [Frown]
_________________________
!

download KiXnet

Top
#68376 - 2002-07-16 04:22 PM Re: Setting all files and directories to Hidden in a specific directory
Radimus Moderator Offline
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.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#68377 - 2002-07-16 04:40 PM Re: Setting all files and directories to Hidden in a specific directory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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 ]
_________________________
!

download KiXnet

Top
#68378 - 2002-07-16 04:49 PM Re: Setting all files and directories to Hidden in a specific directory
Radimus Moderator Offline
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.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#68379 - 2002-07-16 04:54 PM Re: Setting all files and directories to Hidden in a specific directory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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 ]
_________________________
!

download KiXnet

Top
#68380 - 2002-07-17 09:56 PM Re: Setting all files and directories to Hidden in a specific directory
kncowans Offline
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
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.063 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org