Page 1 of 1 1
Topic Options
#12312 - 2001-09-17 10:19 PM using dir to parse files.
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
$filename = Dir("c:\temp")
While $filename <> "" And @ERROR = 0
? $filename
Dir()
Loop

If I run this in debug mode $filename comes up as "." and I see the actual file after dir() . I cant figure out how to get the file into $filename. I am basically trying to parse a directory that has filenames of computers which do not have extensions. I read the manual on dir and the example is not working for me. any help would be great.

[ 17 September 2001: Message edited by: j95661 ]

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#12313 - 2001-09-17 10:39 PM Re: using dir to parse files.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Did you try it exactly as the example shows? In my 3.62 html help file, it has the following example (I aded the Break and Get):
code:

break on
$FileName = Dir("C:\TEMP")
While $FileName <> “” and @ERROR = 0
? $FileName
Dir() ; retrieve next file
Loop

get $



This returned"
Temp

If I modify as follows:

code:

break on
$FileName = Dir("C:\TEMP\*.*")
While $FileName <> “” and @ERROR = 0
? $FileName
Dir() ; retrieve next file
Loop

get $


I get the following results:

...
.FFINQU32.ENU
.New Text Document (2).txt
.New Text Document.txt
.

What do you get?

_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12314 - 2001-09-17 10:46 PM Re: using dir to parse files.
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
I am getting the same results as well. But notice what is happening.

...
.temp.txt
.
the period is being written as the value of $filename
then the file temp.txt is coming after Dir()

that is whats boggling me. I want to get rid of "." and I just want the file name to be in the variable $filename.

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#12315 - 2001-09-17 11:10 PM Re: using dir to parse files.
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
This is whats happening.

$filename = Dir("c:\temp")
while $filename <> "" and @ERROR = 0
? $filename
Dir()
loop

$filename seems to be being set to the root of the directory, which is ".". Dir() is calling the next value in $filename but it is never being used. this is what I tried and it works.

$filename = Dir("c:\temp")
while $filename <> "" and @ERROR = 0
$host = Dir()
? $host
Dir()
loop

this outputs what I want. $filename seems to be acting as an array, but in the example it is never being incremented to the next value, except after dir().

thanks

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#12316 - 2001-09-17 11:16 PM Re: using dir to parse files.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't know if you remember back to the good old DOS days, but every directory always displayed a . entry and a .. entry. This is what you're seeing here. Parse the . and .. and use the others. As for the leading dot, just trim it off. Example:
code:

break on
$FileName = Dir("C:\TEMP\*.*")
While $FileName <> “” and @ERROR = 0
? "$$FileName = " + $FileName
$result = Substr($FileName,2,LEN($FileName))
? "$$result = "$result
Dir() ; retrieve next file
Loop

get $


_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12317 - 2001-09-17 11:17 PM Re: using dir to parse files.
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
oops I spoke too soon. My solution from last post actually increments the value of $filename twice.

well back to the drawing board. I just might have to call a For loop if this will not work.

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#12318 - 2001-09-18 12:31 AM Re: using dir to parse files.
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
I finally see the main part of my problem. Parsing the "." works and getting the filename works, but kixtart doesnt seem to like sending that value to shell.

ex.
Shell "%compspec% /c ping $filename"

that seems to be my problem all along. When I run debug and look at what is being sent to shell, I get the whole directory listing. This must not be a variable that is able to be sent to a shell command. If anyone knows of a way of doing this Id stop ranting about this. :-)

Thanks again

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#12319 - 2001-09-18 12:56 AM Re: using dir to parse files.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Hey, welcome to the club. I've been beating myself up over this one too. I haven't completely wrapped my mind around this thing but this is what I've been able to come up with. I put two test files (PC1 and PC2) in C:\TEMP. Then I run this script and enter PC1, PC2, bla, yada, whatever.
code:

break on
:again
? "Type PC Name and hit [Enter]"
?
Gets $PC

If $PC = ""
goto nomore
endif

$FN = Dir("C:\TEMP\$PC")
While $FN <> "" and @ERROR = 0
beep
? "Found "$FN
Dir()
Loop

goto again
:nomore



Maybe someone can explain it so that I can understand it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12320 - 2001-09-18 01:11 AM Re: using dir to parse files.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Les,

Check out the DIR() function example in the "new" RC3 manual

-Shawn

[hint: a typo was corrected]

Top
#12321 - 2001-09-18 01:50 AM Re: using dir to parse files.
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
Shawn is RC3 going to allow me to send the results to a shell.

break on$
$filename = Dir("c:\temp")
While $filename <> "" and @error =0
Shell "%comspec% /c ping $filename"
$filename = DIR()
loop

if I use that context with 3.61 it doesnt work. That is the current problem sending the result of $filename to shell.

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#12322 - 2001-09-18 02:18 AM Re: using dir to parse files.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Thanks Shawn. Now that I got the syntax right, I revised the script as follows:
code:

break on

$FileName = Dir("C:\TEMP\*.*")
While $FileName <> "" and @ERROR = 0
If len($FileName) > 5
Shell "%comspec% /c ping $filename"
EndIf
$FileName = Dir() ; retrieve next file
Loop


get $



J,
Needed to add the \*.* to make it work, and yes it works under 3.62 and RC3. Also added the If LEN() so that it doesn't try to ping . and .. entries.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#12323 - 2001-09-18 02:49 AM Re: using dir to parse files.
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
Thanks a bunch you guys.. I was running an older version of kixstart than I thought. Downloaded RC3 and its working great.

Thanks again for you help.

_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#12324 - 2001-09-18 05:20 AM Re: using dir to parse files.
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
here is an example on how to list only the files in a folder (with out having to use the LEN command

You do not have to worry about directory entries like"." or ".." or any other directory listing that may exist in the folder.

code:

$Folder = "c:\"

;set the initial DIR() pointer
$return = dir($folder + "*.*")

? "Now listing all files in " + $folder
while @error = 0

;this will only be true for files, to list only folders set it to equal 16
IF (getfileattr($folder + $return) & 16) = 0
? $return
endif

;get the next item in the folder
$return = dir()
loop


Bryce

Top
#12325 - 2001-10-21 06:12 AM Re: using dir to parse files.
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear j95661,

The problem wasn't: you are running an older version of kixtart, but the
example in your the documentation wasn't correct.
In kixtart 3.63 release it works great. Older versions 3.60 .. 3.62 not checked.
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
Page 1 of 1 1


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

Who's Online
0 registered and 847 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.063 seconds in which 0.025 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