none
File.GetFiles(path) RRS feed

  • Question

  • Hi All,

    I'm trying to check if a file is already saved in a directory.  I think I need to use File.GetFiles(path) and copy each returned item into and array then check that against the new path.  If it already exists chose a new name and try again or the file name is new, saved the file. 

    How do I get each item from File.GetFiles(path) into an array?

    Thanks for your help.

    Barry

    Tuesday, May 31, 2016 6:25 PM

Answers

  • File.GetFiles(path)  already returns all the found filepaths as an array.

    Try sample (with current program directory as 'path'):

    path = Program.Directory

    arrFiles = File.GetFiles(path)
    nFiles = Array.GetItemCount(arrFiles)
    TextWindow.WriteLine(nFiles +" found in "+ path)
    TextWindow.WriteLine("")
    For n = 1 To nFiles
      TextWindow.WriteLine(n + ". file: "+ arrFiles[n])
    EndFor

    • Marked as answer by Baz Coop Tuesday, May 31, 2016 6:52 PM
    Tuesday, May 31, 2016 6:44 PM
    Answerer

All replies

  • File.GetFiles(path)  already returns all the found filepaths as an array.

    Try sample (with current program directory as 'path'):

    path = Program.Directory

    arrFiles = File.GetFiles(path)
    nFiles = Array.GetItemCount(arrFiles)
    TextWindow.WriteLine(nFiles +" found in "+ path)
    TextWindow.WriteLine("")
    For n = 1 To nFiles
      TextWindow.WriteLine(n + ". file: "+ arrFiles[n])
    EndFor

    • Marked as answer by Baz Coop Tuesday, May 31, 2016 6:52 PM
    Tuesday, May 31, 2016 6:44 PM
    Answerer
  • Thanks very much. 

    Tuesday, May 31, 2016 6:52 PM
  • also try this simple program: ( you will need to install LitDev extension )

    with the DIALOG BOX you can see all others files saved before.

    it will open the windows dialog box to open a file in the picture folder directory, and will look only for JPG or BMP in my example,

    GraphicsWindow.top= 0
    GraphicsWindow.left= 0
    GraphicsWindow.Height=768
    GraphicsWindow.Width=1366

    path=LDFile.PicturesFolder
    image=LDDialogs.OpenFile("1=jpg;2=bmp",path)
    GraphicsWindow.DrawresizedImage(image, 100, 100,600,400) 


    • Edited by YLedEditor Tuesday, May 31, 2016 7:04 PM
    Tuesday, May 31, 2016 7:00 PM
    Answerer