locked
Programing help RRS feed

  • Question

  • I'm trying to write code to check a directory to see if a text files exist in it, is it does then the program proceeds, if not perhaps a text window stating it does not exist. Being new to programing,i'm not quite sure the best way to do this, maybe a text.startswith or maybe an array. I'm not very comfortable with arrays so here is what I started:

    path = Program.Directory
    ordernumber = "1 of 1.txt"    'There is a text file in the directory with this name
    ItemCheck = File.GetFiles (path + "\Items list\")
    OrderCheck = Text.StartsWith(ItemCheck, ordernumber)
    TextWindow.Write (OrderCheck)
    TextWindow.Write (ItemCheck )

    The itemcheck list all the files in the directory but the ordercheck reads failed eventhough there is a file with the ordernumber name.

    Any suggestions is greatly appreciated,

    Steve

    Monday, September 27, 2010 4:12 PM

Answers

  • Try this:

    path = Program.Directory

    FileToFound = "1 of 1.txt"    'There is a text file in the directory with this name
    Items = File.GetFiles (path + "\Items list")
    PathLenght = Text.GetLength(path + "\Items list") + 2
    For I = 1 To Array.GetItemCount(Items) + 1 'use for loop to check all files
      If (Text.GetSubTextToEnd(Items[I], PathLenght) = FileToFound) Then   
        TextWindow.WriteLine("File Found")
      EndIf 
    EndFor

    Your problems are in lines 3 and 4.

     


    Sorry My Bad English
    • Proposed as answer by Oskariok Monday, September 27, 2010 4:30 PM
    • Marked as answer by SFC123 Monday, September 27, 2010 4:35 PM
    Monday, September 27, 2010 4:29 PM

All replies

  • Try this:

    path = Program.Directory

    FileToFound = "1 of 1.txt"    'There is a text file in the directory with this name
    Items = File.GetFiles (path + "\Items list")
    PathLenght = Text.GetLength(path + "\Items list") + 2
    For I = 1 To Array.GetItemCount(Items) + 1 'use for loop to check all files
      If (Text.GetSubTextToEnd(Items[I], PathLenght) = FileToFound) Then   
        TextWindow.WriteLine("File Found")
      EndIf 
    EndFor

    Your problems are in lines 3 and 4.

     


    Sorry My Bad English
    • Proposed as answer by Oskariok Monday, September 27, 2010 4:30 PM
    • Marked as answer by SFC123 Monday, September 27, 2010 4:35 PM
    Monday, September 27, 2010 4:29 PM
  • Thanks Oskariok!

    That works, you make this look easy, (it took me hours with no results).

    Monday, September 27, 2010 4:35 PM
  • Hi Oskariok,

    One more question, Is it possible for the array to find the Filetofound if it is a part of the file name in the items list directory?

    Monday, September 27, 2010 5:41 PM
  • Do you mean this

    'Text.IsSubText is really Text.Contains(Text,TextToContain)
    path = Program.Directory

    PartOfNameToFound = "1" 'Part to found in any file name.
    Items = File.GetFiles (path + "\Items list")
    PathLenght = Text.GetLength(path + "\Items list") + 2
    For I = 1 To Array.GetItemCount(Items) + 1 'use for loop to check all files
      CurrentFileName = Text.GetSubTextToEnd(Items[I], PathLenght)
      If (Text.IsSubText(CurrentFileName,PartOfNameToFound) = "true") Then  'If current file name contains  PartOfNameToFound
        TextWindow.WriteLine("File Found")
      EndIf
    EndFor

    Sorry My Bad English
    Monday, September 27, 2010 5:59 PM
  • Yes, that's what I'm looking for!

    Thanks again for your help.

    Monday, September 27, 2010 6:09 PM