Jump to content
Sign in to follow this  
MOCEwez

Trouble getting FileFindFirstFile to work

Recommended Posts

MOCEwez

[RESOLVED]

Hi,

I have been searching the forums here for a while now, but can't find the information I need.

A program of ours reads in XML files.

If there's a problem importing the data then that program creates another XML file with the problem items.

The file created contains the orginal filename plus it's own added identifier.

Each XML file has an unique name.

e.g. 100_S_DPO_Work_311008_143417.XML

I am 100% sure that the file exists.

CODE
Dim $FileName = "100_S_DPO_Work_311008_143417.XML"

Dim $PathToLook = "C:\Export\Failed\"

Dim $Found

Local $ShortFileName = StringLeft($FileName,stringlen($FileName) - 4)

FileChangeDir($PathToLook)

$Found= FileFindFirstFile($ShortFileName & "*.xml")

if $Found <> -1 Then

msgbox(0,"File found","Congratulations!!")

Else

MsgBox(0,"File not found", "Bummer :-(")

EndIf

I have also tried $PathToLook without the "\" and also searching the file without the use of a variable.

Help on this would be much appreciated.

Edited by MOCEwez

Do not today what you can get someone else to do tomorrow.

Share this post


Link to post
Share on other sites
FaT3oYCG

CODE
Dim $FileName = "100_S_DPO_Work_311008_143417.XML"

Dim $FileName = "100_S_DPO_Work_311008_143417.XML"

Dim $PathToLook = "C:\Export\Failed\"

Dim $Found

Local $ShortFileName = StringLower(StringLeft($FileName, StringLen($FileName) - 4))

FileChangeDir($PathToLook)

$Found = FileFindFirstFile($ShortFileName & ".xml")

If $Found <> -1 Then

MsgBox(0, "File found", "Congratulations!!")

Else

MsgBox(0, "File not found", "Bummer :-(")

EndIf

you need to use StringLower() to make sure that the file name you are inputting is always lowercase therfore when you check it against .xml it will return true because the file names actual extension is .XML and .XML <> .xml therefore using string to lower will amke sure that the file is always found if it exists

Edited by FaT3oYCG

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites
MOCEwez

you need to use StringLower() to make sure that the file name you are inputting is always lowercase therfore when you check it against .xml it will return true because the file names actual extension is .XML and .XML <> .xml therefore using string to lower will amke sure that the file is always found if it exists

Thanks for the tip, but it's not working for me.

I have tried both upper and lower casing (Including .xml) to no avail.

Yoru snippet is missing the wildcard which is necessary. There are hundreds of .XML files in this folder.

Here's an actual file name.

Import_100_S_DPO_Work_311008_143417_100_glentries_31-10-08_14 35 15.XML

might it have something to do with the "_"'s?


Do not today what you can get someone else to do tomorrow.

Share this post


Link to post
Share on other sites
FaT3oYCG

what is your program required to do, find all of the files in the folder and show them on a gui somewhere?

EDIT 1:

p.s. FileFindFirsFile() only finds the first file as the name says with the criteria

EDIT 2:

here is some code that should display all of the files that are in that directory with the functions used but as i dont know what you want to do with the data here is an example you can run and tell me what happens

CODE

Dim $PathToLook = "C:\Export\Failed\"

#include <File.au3>

#include <Array.au3>

$FileList = _FileListToArray($PathToLook, "*.xml")

If @error = 1 Then

MsgBox(0, "Warning!!!", "No Files or Folders Found.")

Exit

EndIf

_ArrayDisplay($FileList, "$FileList")

Edited by FaT3oYCG

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites
MOCEwez

what is your program required to do, find all of the files in the folder and show them on a gui somewhere?

EDIT 1:

p.s. FileFindFirsFile() only finds the first file as the name says with the criteria

EDIT 2:

here is some code that should display all of the files that are in that directory with the functions used but as i dont know what you want to do with the data here is an example you can run and tell me what happens

CODE

Dim $PathToLook = "C:\Export\Failed\"

#include <File.au3>

#include <Array.au3>

$FileList = _FileListToArray($PathToLook, "*.xml")

If @error = 1 Then

MsgBox(0, "Warning!!!", "No Files or Folders Found.")

Exit

EndIf

_ArrayDisplay($FileList, "$FileList")

My program will call another .exe to import XML files with purchase or selling invoices into our financial software.

If the financial software comes accross any problem invoices then those invoices are entered into another XML file and are not imported.

The second XML file is what i'm looking for. If found then an email will be sent to the user.

If it's the purchase invoices that had errors then I inform one user, otherwise I inform another.

The full file name of the first XML is in the filename of the second XML.

As the file names are all unique, the FileFindFirsFile() function is what would be best.

I do use _FileListToArray to get all the file names of the first XML files.

I s'pose I could use it again, but I don't think it's very efficient for looking for one file.

Thanks for your help so far!


Do not today what you can get someone else to do tomorrow.

Share this post


Link to post
Share on other sites
jerem488

Does your file is hidden?


Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Share this post


Link to post
Share on other sites
MOCEwez

Hi,

I found out what the problem was.

Quite embarrassing really....

The second XML file (Ceated by the financial software) adds the prefix "Import_" to the original file name.

Thus I needed either 2 wildcards to search or add "Import_" as a prefix to the filename I need to find.

It happens that this is possible with FileExists() as well.

Works like a charm now.

FaT3oYCG,

Your comments about FileFindFirstFile worked as well (With the correct file name part)

Edited by MOCEwez

Do not today what you can get someone else to do tomorrow.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×