locked
Program Help RRS feed

  • Question

  • I have a program where I get a file from one destination and put a copy of the file in another folder (an image file in this case). I would like to use the copied file in my program via the imagelist.loadimage command. My problem is that I don't know how to retieve the file because the name is not known until it is copied into the folder. So as it is now I'm using the image from the origonal source instead of the image copied to the folder.

    Here is my code so far;

    Sub FurnImageLoad
      FurnImageGet = Dialogs.AskForFile()  'a Fremy tool
      File.DeleteDirectory (Path + "\Furn images\" + ItemNo)  'deletes any previously made directory with the same item no.
      File.CreateDirectory (Path + "\Furn images\" + ItemNo)
      File.CopyFile(FurnImageGet,Path + "\Furn images\" + ItemNo)
      FurnImage = ImageList.LoadImage (FurnImageGet )' origonal source
      GraphicsWindow.DrawResizedImage (FurnImage,330,335,150,150)
    endsub

    Any help is greatly appreciated.
    Thanks,
    Steve
    Sunday, February 28, 2010 5:24 AM

Answers

  • The File.CopyFile need to put a file, not a directory ("Path + "\Furn images\" + ItemNo " is a directory - you have just created it).

    The following adds the file name from the original file in the new directory, then reads this file.  I modified slightly to not be a subroutine to test quickly.

    GraphicsWindow.Show()
    path = "C:\temp"
    ItemNo = "Item1"

    File.DeleteDirectory (Path + "\Furn images\" + ItemNo)  'deletes any previously made directory with the same item no.
    File.CreateDirectory (Path + "\Furn images\" + ItemNo)

    FurnImageGet = Dialogs.AskForFile()  'a Fremy tool

    ' Get the file name not including the path (strip the path)
    fileName = FurnImageGet
    pos = Text.GetIndexOf(fileName,"\")
    While (pos > 0)
      fileName = Text.GetSubTextToEnd(fileName,pos+1)
      pos = Text.GetIndexOf(fileName,"\")
    EndWhile

    'Set the saved file and then save it
    savedFurnImage = Path + "\Furn images\" + ItemNo + "\" + fileName
    File.CopyFile(FurnImageGet,savedFurnImage)

    'Read the saved file and draw it
    FurnImage = ImageList.LoadImage(savedFurnImage) ' saved source
    GraphicsWindow.DrawResizedImage(FurnImage,330,335,150,150)

    • Marked as answer by SFC-P33A Sunday, February 28, 2010 10:22 PM
    Sunday, February 28, 2010 11:59 AM

All replies

  • The File.CopyFile need to put a file, not a directory ("Path + "\Furn images\" + ItemNo " is a directory - you have just created it).

    The following adds the file name from the original file in the new directory, then reads this file.  I modified slightly to not be a subroutine to test quickly.

    GraphicsWindow.Show()
    path = "C:\temp"
    ItemNo = "Item1"

    File.DeleteDirectory (Path + "\Furn images\" + ItemNo)  'deletes any previously made directory with the same item no.
    File.CreateDirectory (Path + "\Furn images\" + ItemNo)

    FurnImageGet = Dialogs.AskForFile()  'a Fremy tool

    ' Get the file name not including the path (strip the path)
    fileName = FurnImageGet
    pos = Text.GetIndexOf(fileName,"\")
    While (pos > 0)
      fileName = Text.GetSubTextToEnd(fileName,pos+1)
      pos = Text.GetIndexOf(fileName,"\")
    EndWhile

    'Set the saved file and then save it
    savedFurnImage = Path + "\Furn images\" + ItemNo + "\" + fileName
    File.CopyFile(FurnImageGet,savedFurnImage)

    'Read the saved file and draw it
    FurnImage = ImageList.LoadImage(savedFurnImage) ' saved source
    GraphicsWindow.DrawResizedImage(FurnImage,330,335,150,150)

    • Marked as answer by SFC-P33A Sunday, February 28, 2010 10:22 PM
    Sunday, February 28, 2010 11:59 AM
  • Steve,

    Here's a slight alternative to LitDev's offering.  Ideally it would be great if Fremy could add a new Text.GetSubText() function which had an additional 'direction' parameter, allowing searches to go backwards as well as forwards, which is the function you need to be able to pull out just the filename element of the source path.

    Anyway, here's a subroutine'd offering... remember to change the DestPath value...

    ItemNo = 1
    
    'copy an image
    FurnImageLoad()
    
    'show path values
    TextWindow.WriteLine("Source   = " + srcPath)
    TextWindow.WriteLine("Path     = " + path)
    TextWindow.WriteLine("Filename = " + filename)
    TextWindow.WriteLine("New file = " + destPath+"\"+filename)
    TextWindow.WriteLine("")
    
    ' display copied image
    FurnImage = ImageList.LoadImage (destPath+"\"+filename)
    GraphicsWindow.DrawResizedImage (FurnImage,50,50,150,150)
    
    
    Sub FurnImageLoad
      destPath = "C:\Users\DaveyWavey\Desktop\Furn images\" + ItemNo
      srcPath = Dialogs.AskForFile()  'a Fremy tool
      path = srcPath                   ' only doing this to preserve the source path
      getPathnFilename()
      File.DeleteDirectory (destPath)  'deletes any previously made directory with the same item no.
      File.CreateDirectory (destPath)
      File.CopyFile(srcPath,destPath)
    endsub
    
    Sub getPathnFilename
      ' requires: variable 'Path' containing path and filename
      ' returns: variable 'Path' containing just path (with trailing '\')
      '                 variable 'Filename' containing just filename
      
      gpfPos = Text.GetLength(path)
      
      While gpfPos > 1
        If Text.GetSubText(path, gpfPos, 1) = "\" Then
          ' get path and filename
          filename = Text.GetSubTextToEnd(path, gpfPos+1)
          path     = Text.GetSubText(path, 1, gpfPos)
          ' found what we're looking for, so cancel search
          gpfPos = 0
        EndIf
        gpfPos = gpfPos -1
      EndWhile
    EndSub
      

    Sunday, February 28, 2010 12:12 PM
  • Thank you Davey for your help!
    Sunday, February 28, 2010 10:25 PM
  • Thank you LitDev, works like a charm.
    Sunday, February 28, 2010 10:26 PM