Problem with DIRECTORY() function

Problem with DIRECTORY() function

Postby codemaker » Fri Feb 17, 2012 1:05 pm

I use xHarbour and some Web-library for my Web applications for many years by now.

I have one folder which holds the PDF files for calculated W2 forms.
Each file name starts with the client code, which is 3 character.
The listed files in folder looks like this (part of listing):

A27_0154_USW2_4CR_1231.PDF
A27_0154_USW2_4CR_1231.PDF
A28_0154_USW2_4CR_1231.PDF
A28_0154_USW2_4CR_1231.PDF
A29_0154_USW2_4CR_1231.PDF
A29_0154_USW2_4CR_1231.PDF
A29_0154_USW2_4CR_1231.PDF
A29_0154_USW2_4CR_1231.PDF
A29_0154_USW2_4CR_1231.PDF
A29_0154_USW2_4CR_1231.PDF
A24_0154_USW2_4CR_1231.PDF
A24_0154_USW2_4CR_1231.PDF
A24_0154_USW2_4CR_1231.PDF
A24_0154_USW2_4CR_1231.PDF
A29_0154_USW2_4CR_1231.PDF
A24_0154_USW2_4CR_1231.PDF
...

The folder name is for example: cFind := "c:\pdffiles\W2forms\"
The client code I want to extract: cUserID := "A29"
When I want to extract only the PDF files which starts with client code for example "A29" I do it like this
af1 := cFind + cUserID + "*.PDF"
aMyFiles := DIRECTROY( af1 )

I expect in "aMyFiles" array all PDF files which name starts with "A29"
On my huge surprise the array contains something like tihs, after I made some debug breakpoint:
Image

I cannot even think to explain how this happened???
This error cause me a lot of problems, I simply cannot relay on DIRECTORY() function any more. If some clients can see some other clinets W2 forms, I can close my business in the payroll area.... So I disabled for now this feature.

I tested this behaviour and select another user ID, for example "A24" and it shows all A24 but also some of A29 and A27... And so forth.
For some user ID it shows ok, only what I select to be the USer ID....

I can't find any pattern, maybe the length of file names??

For now I will "filter" this wrong results
Code: Select all  Expand view

FOR := 1 to LEN(aMyFiles)
      IF UPPER(SUBS(aMyFiles[i][1],1,3) == UPPER(cUserID)
            - use this element (file) for workig with
      ENDIF
NEXT i
 

which is not I ever dreamed of as necessary after the DIRECTORY() function call...
Not to mention it took me almost 10 days of hard tries to find out what causes the list to be "mixed" with different user ID PDF files. Finally, I was desperate and checked what exactly comes out as the result of DIRECTORY() function. It is not enaugh to say I was astonished..

Any similar experiences?
I am totaly confused...
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Problem with DIRECTORY() function

Postby Rick Lipkin » Fri Feb 17, 2012 2:16 pm

CodeMaker

Directory() is a (x)Harbour function and not part of FWH .. Have you updated or changed your (x)Harbour compiler recently ?

The xHarbour newsgroup is :
http://groups.google.com/group/comp.lan ... pics?gvc=2

The Harbour newsgroup is :
http://groups.google.com/group/harbour-users/topics

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Problem with DIRECTORY() function

Postby FranciscoA » Fri Feb 17, 2012 10:03 pm

Codemaker,

I think this function retrieves entire names of files, not partially names of them. Maybe I Wrong.

I allways have used the technic you describes, on others similar cases.

In the other hand, I think this could be a new feature of this function for to be implementation, if it so considers the xHarbour's creators.

Regards
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2158
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Problem with DIRECTORY() function

Postby codemaker » Fri Feb 17, 2012 10:47 pm

Yes, I was confused because whatever kind of file names this function retrieves, it should obey the given pattern.
If this pattern is "A26*.PDF" I don't see any reason this function return any other file name which does not start with "A26"
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Problem with DIRECTORY() function

Postby Enrico Maria Giordano » Sun Feb 19, 2012 10:14 am

To blame the compiler is the easy way, almost the wrong one. :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Problem with DIRECTORY() function

Postby Antonio Linares » Sun Feb 19, 2012 1:29 pm

Boris,

I think it may be related with the use of long filenames because this example works fine with both Harbour and xHarbour:

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local aFiles := Directory( "b*.prg" )

   MsgInfo( Len( aFiles ) )

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42087
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Problem with DIRECTORY() function

Postby ukoenig » Sun Feb 19, 2012 2:14 pm

Antonio,

YES, it seems to be a Problem with long Filenames.

Image

It means to scan all Array-elements for "A29" ? :

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Problem with DIRECTORY() function

Postby codemaker » Mon Feb 20, 2012 12:49 am

Just a sample what exactly is wrong here.
It is the way how Windows OS handle the long filenames.

1. Look how windows "translate" the long file names and creates the short file names abreviation:
Image
Notice how the short names all start with "A29" for no logical reason

2. Now, according with the method Windows OS creates short file names abowe, this is what we get when using DIRECTORY("A29*.PDF")
Image


And I am affraid this is not the end:
This "filtering method" when we use long file names is probably affected by
COPY a29*.pdf c:\somefolder - who nows what will be copied

Also, even biger problem, sonsider the nightmare if we delete the files by using "filtering":
DEL a29*.pdf - we will finished with some other files deleted too!!!!!

The same potentialo problem with
REN a29*.pdf a25*.pdf - who knows what the result will be.....

Scary.
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Problem with DIRECTORY() function

Postby StefanHaupt » Mon Feb 20, 2012 8:56 am

Codemaker,

this sample is working fine here. See the images.

Code: Select all  Expand view
#include "Fivewin.ch"
#include "xBrowse.ch"

function main ()

  local aDir, aDirAll
  local cFind := ".\Testdir\"
  local cUserID := "
A29"
  local af1 := cFind + cUserID + "
*.PDF"

  aDir := Directory (af1)
  ? "
Searching " + af1, "Found: " + Str (Len(aDir))
  xBrowser aDir

  aDirAll := Directory (cFind+"
*.pdf")
  ? "
Searching all" + af1, "Found: " + Str (Len(aDirAll))
  xBrowser aDirAll


  RETURN (0)


Image
Image
Image
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Problem with DIRECTORY() function

Postby Otto » Mon Feb 20, 2012 9:01 am

Hello Boris,

As all is that complex it is very important to have good beta testers for your software.

BTW, did you try using Lfn2Sfn(cDir) with the directory-function?

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6331
Joined: Fri Oct 07, 2005 7:07 pm

Re: Problem with DIRECTORY() function

Postby Enrico Maria Giordano » Mon Feb 20, 2012 9:07 am

codemaker wrote:And I am affraid this is not the end:
This "filtering method" when we use long file names is probably affected by
COPY a29*.pdf c:\somefolder - who nows what will be copied

Also, even biger problem, sonsider the nightmare if we delete the files by using "filtering":
DEL a29*.pdf - we will finished with some other files deleted too!!!!!

The same potentialo problem with
REN a29*.pdf a25*.pdf - who knows what the result will be.....

Scary.


I can't believe this! Can you test the above commands with your filenames and let us know, please?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8712
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Problem with DIRECTORY() function

Postby codemaker » Mon Feb 20, 2012 9:57 am

Otto wrote:Hello Boris,

As all is that complex it is very important to have good beta testers for your software.

BTW, did you try using Lfn2Sfn(cDir) with the directory-function?

Best regards,
Otto

Hi Otto,
All my software is tested for 8 years (web app) and more than 14 years (desktop)
Two months ago, I implemented this new function to print PDF from WEB and then I spoted the problem. Therefore, I am sure, it is not my app problem, epsecially one line of code cannto be written wrong ( DIRECTORY(cFilterString)

Then I tested the same PDF access from desktop application - same problem.

The I checked what DOS shows and the images says all. DOS simply create the short fle name

I didn't try Lfn2Sfn() function yet and I don't think I will, because I will additionaly filter the DIRECTORY() returned array and finally have the correct names

Regards
Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Problem with DIRECTORY() function

Postby codemaker » Mon Feb 20, 2012 9:59 am

Enrico Maria Giordano wrote:
codemaker wrote:And I am affraid this is not the end:
This "filtering method" when we use long file names is probably affected by
COPY a29*.pdf c:\somefolder - who nows what will be copied

Also, even biger problem, sonsider the nightmare if we delete the files by using "filtering":
DEL a29*.pdf - we will finished with some other files deleted too!!!!!

The same potentialo problem with
REN a29*.pdf a25*.pdf - who knows what the result will be.....

Scary.


I can't believe this! Can you test the above commands with your filenames and let us know, please?

EMG


I will today and will post here
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Re: Problem with DIRECTORY() function

Postby StefanHaupt » Mon Feb 20, 2012 10:32 am

codemaker wrote:And I am affraid this is not the end:
This "filtering method" when we use long file names is probably affected by
COPY a29*.pdf c:\somefolder - who nows what will be copied

Also, even biger problem, sonsider the nightmare if we delete the files by using "filtering":
DEL a29*.pdf - we will finished with some other files deleted too!!!!!

The same potentialo problem with
REN a29*.pdf a25*.pdf - who knows what the result will be.....

Scary.


Boris,

I don´t see any wrong behavior, neither from dos nor from xHarbour. Did you test my sample ?

Dos-commands are also working here (Win7)

Image
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Problem with DIRECTORY() function

Postby codemaker » Mon Feb 20, 2012 12:05 pm

StefanHaupt wrote:
Boris,

I don´t see any wrong behavior, neither from dos nor from xHarbour. Did you test my sample ?

Dos-commands are also working here (Win7)

Image


Stefan,
This is exactly what scares me.
On some system, it works, on some other doesn't
I cannot find the difference.

For example, my WebApp is running on many servers (computers), starting from XP and then Wndows server 2003, Windows server 2008, also on Windows7....
Some of my clients doesn't complain at all, some of them does (one of them Windows server 2003). My machine (Windows 7) also shows the problem, yours doesn't....

I didn't test your sample, because it is the same as what I posted, I don't see any basic difference?
Your sample works ok, and your DOS shows properly.
Mine doesn't show the proper result because I can see DOS shows problem either...

I suspect the cause of the problem is in Windows OS which handles short-long file names on some way which the function DIRECTORY() interprets wrongly, while following DOS OS. This will not be solved or changed by M$, so what's left is up to the creators of xHB, maybe they should add the code which additionaly filters the resulting array from DIRECTORY() function...

I am not sure what to say, but to use the additional filtering before presenting the result to the program user.

ragards
Boris
User avatar
codemaker
 
Posts: 208
Joined: Wed Dec 03, 2008 4:48 pm
Location: Belgrade, Serbia

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 107 guests