Page 1 of 1 1
Topic Options
#154928 - 2006-01-09 11:41 PM Help with Dir()
daniel1982 Offline
Getting the hang of it

Registered: 2005-03-23
Posts: 77
Loc: Sydney, Australia
Hi All,

any ideas why this is not working? @error returns 0 for both Dir() calls, but it gets in an infinite loops at ?"hello5:" and the filename is simply "."?

Code:
 
break on
Dim $Directory $Directory = "\\server\share"
Dim $f $f = CreateObject("Scripting.FileSystemObject")

?"hello1"
If Exist ($Directory)
$Folder = Dir($Directory)
?"Hello2: " + $Folder + " error: " + @error

While $Folder <> "" and @ERROR = 0 ;and $f.IsFolder($Directory +
$Folder)
?"hello3"
If $Folder <> "." or $Folder <> ".."
$FileName = Dir($Directory + $Folder, 1) ; retrieve next file
?"hello4 error: " + @error
While $FileName <> "" or $Filename <> "." or $FileName <> ".."
and @error = 0
If $Filename <> "." or $Filename <> ".."
? "Directory: " + $Directory + $Folder
?"hello5:" + $FileName
If Right($FileName, 4) = ".htm"
?$Filename + " is htm file"
EndIf

EndIf
$FileName = Dir($Directory + $Folder, 1)
? " Getting new filename: " + $Filename
Loop
EndIf
$Folder = Dir($Directory)
Loop
endIf


Top
#154929 - 2006-01-10 12:05 AM Re: Help with Dir()
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
you are missing the whole $index thingy from the instructions
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#154930 - 2006-01-10 12:09 AM Re: Help with Dir()
daniel1982 Offline
Getting the hang of it

Registered: 2005-03-23
Posts: 77
Loc: Sydney, Australia
Code:
$FileName = Dir($Directory + $Folder, 1) 



Isn't that the one?

Top
#154931 - 2006-01-10 12:16 AM Re: Help with Dir()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
$FileName = Dir() ;just like in the example
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154932 - 2006-01-10 12:26 AM Re: Help with Dir()
daniel1982 Offline
Getting the hang of it

Registered: 2005-03-23
Posts: 77
Loc: Sydney, Australia
So it should be $FileName = Dir("", 1) and $Folder = Dir()? This still seems to be giving me the same problem...?
Top
#154933 - 2006-01-10 01:20 AM Re: Help with Dir()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There's more to it than that. I cannot make sense of your code and what you are trying to do.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154934 - 2006-01-10 04:15 AM Re: Help with Dir()
daniel1982 Offline
Getting the hang of it

Registered: 2005-03-23
Posts: 77
Loc: Sydney, Australia
This is what I'm trying to do:

$Directory is a directory full of Folders. within each of these folders is a number of .htm files. I basically need to copy each of these .htm files, parse them a bit and create a new .shtm file in the same directory. What i've attempted to do so far is just get the filenames to parse.

ie:

Code:

Dir(The directory containing the folders)
While There are no errors
Dir(the folder underneath the original directory)
While there are no erros
?Show the filename
Dir(the folder underneath the original directory)
Loop
Dir(the directory containing the folders)
Loop



Does that make more sense?

Top
#154935 - 2006-01-10 04:39 AM Re: Help with Dir()
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Use the DirPlus() UDF.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#154936 - 2006-01-10 04:46 AM Re: Help with Dir()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that is actually so simple that it's possible to code it with the dir alone, just like his pseudo-code showed.
_________________________
!

download KiXnet

Top
#154937 - 2006-01-10 04:54 AM Re: Help with Dir()
daniel1982 Offline
Getting the hang of it

Registered: 2005-03-23
Posts: 77
Loc: Sydney, Australia
OK, so i've taken out the debug statements, and added back in the fso query, can anyone tell me why this isn't working?

Code:
break on
Dim $Directory $Directory = "\\nucnas02\intratst_content\busservices\procurement_home\pres\ProductGuide\"
Dim $f $f = CreateObject("Scripting.FileSystemObject")

If Exist ($Directory)
$Folder = Dir($Directory)

While $Folder <> "" and @ERROR = 0 and $f.IsFolder($Directory + $Folder)
If $Folder <> "." or $Folder <> ".."
$FileName = Dir($Directory + $Folder, 1) ; retrieve next file
While $FileName <> "" or $Filename <> "." or $FileName <> ".." and @error = 0
If $Filename <> "." or $Filename <> ".."
If Right($FileName, 4) = ".htm"
?$Filename + " is htm file"
EndIf

EndIf
$FileName = Dir("", 1)
Loop
EndIf
$Folder = Dir()
Loop
endIf


Top
#154938 - 2006-01-10 05:47 AM Re: Help with Dir()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, this modification works:
Code:

break on
Dim $Directory $Directory = "C:\Documents and Settings\***.JOOEL\Omat tiedostot\kixtart\"

If Exist ($Directory)
$Folder = Dir($Directory)

While $Folder <> "" and @ERROR = 0
If $Folder <> "." AND $Folder <> ".." AND (getFileAttr($Directory + $Folder) & 16)
$FileName = Dir($Directory + $Folder, 1) ; retrieve next file
While $FileName <> "" and @error = 0
If $Filename <> "." or $Filename <> ".."
If Right($FileName, 4) = ".htm"
?$Filename + " is htm file"
EndIf

EndIf
$FileName = Dir("", 1)
Loop
EndIf
$Folder = Dir()
Loop
endIf

get $



see what I changed?
not much.


Edited by Jooel (2006-01-10 07:11 AM)
_________________________
!

download KiXnet

Top
#154939 - 2006-01-10 05:51 AM Re: Help with Dir()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
btw, if you want, you can let kixtart check the html files by using this code instead:
Code:

break on
Dim $Directory $Directory = "C:\Documents and Settings\***.JOOEL\Omat tiedostot\kixtart\"

If Exist ($Directory)
$Folder = Dir($Directory)

While $Folder <> "" and @ERROR = 0
If $Folder <> "." AND $Folder <> ".." AND (getFileAttr($Directory + $Folder) & 16)
$FileName = Dir($Directory + $Folder + "\*.htm", 1) ; retrieve next file
While $FileName <> "" and @error = 0
?$Filename + " is htm file"
$FileName = Dir("", 1)
Loop
EndIf
$Folder = Dir()
Loop
endIf

get $



Edited by Jooel (2006-01-10 07:10 AM)
_________________________
!

download KiXnet

Top
#154940 - 2006-01-10 06:33 AM Re: Help with Dir()
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Quote:

***.JOOEL




You know you can be just Jooel on your own system

But that's a nice long path to type at dos console.

[censored by jooel ]


Edited by Jooel (2006-01-10 07:08 AM)

Top
#154941 - 2006-01-10 06:36 AM Re: Help with Dir()
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Daniel, now that you have the listing do you know how to use for your purposes or do you need assistance with the parsing?

If so please give a bit more of an example of what you want to do from start to finish.

Thanks, and good luck.

Top
#154942 - 2006-01-10 07:09 AM Re: Help with Dir()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yes, doc, it's a bitch of you need to type it.
I never do.
and, JOOEL obviously in that is the comp name denoting a local account.
_________________________
!

download KiXnet

Top
#154943 - 2006-01-10 10:40 AM Re: Help with Dir()
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
LOL - I thought it was an encryption line
Top
#154944 - 2006-01-10 03:12 PM Re: Help with Dir()
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
Code:
Dim $Directory, $file

$Directory = "\\nucnas02\intratst_content\busservices\procurement_home\pres\ProductGuide\"

for each $file in dirplus($directory,'/ad /f htm')
? $file.name " " $file.path
next


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 400 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.072 seconds in which 0.026 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