locked
File.CopyFile does not work (again...) RRS feed

  • Question

  • Hello guys,

    the File.CopyFile command is trolling me again.

    I can't explain why it wont work. The path looks fine for me, and if I use the same path without reading it from a textfile it works well. The path is the same if I read it from a textfile, but it just doesn't work.

    My code:

    AutoupdaterVersion = "1.0"
    CheckFileDestination = Program.Directory + "\\Note Program.txt"
    Zeilen = File.ReadLine(CheckFileDestination, 2)
    HalbeZeilen = Zeilen/2
    PfadStart = 2+HalbeZeilen+1
    LinkEnde = PfadStart-1
    GesamtZeilen = Zeilen+2
    a()
    
    Sub a
      For i = 3 To LinkEnde
        i2 = i-2
        i3 = i3+0
        UpdateFileLink[i] = File.ReadLine(CheckFileDestination, i) 'Link der herunterzuladenden Datei wird eingelesen
        TextWindow.WriteLine("Downloading file: " + UpdateFileLink[i])
        UpdateFileTemp[i] = Network.DownloadFile(UpdateFileLink[i])  'Die Datei wird in ein temporäres Verzeichnis geladen
        TextWindow.Title = "AutoUpdater v" + AutoupdaterVersion + "   Downloaded: " + i2 + "/" + HalbeZeilen + "   Installed: " + i3 + "/" + HalbeZeilen
        Program.Delay(1000)
      EndFor
      For e = PfadStart To GesamtZeilen
        e2 = e-LinkEnde
        e3 = e2+2
        'TextWindow.WriteLine("e="+e+" e2="+e2+" e3="+e3) 'DEBUG
        If Text.StartsWith(File.ReadLine(CheckFileDestination, e), "PD ") = "True" Then
          Pfadteil = Text.GetSubTextToEnd(File.ReadLine(CheckFileDestination, e), 4)
          TextWindow.WriteLine(PfadTeil) 'DEBUG
          TextWindow.WriteLine(Program.Directory+Pfadteil) 'DEBUG
          TextWindow.WriteLine("Installing file: " + Pfadteil)
          UpdateFileInstallation[e2] = File.CopyFile(UpdateFileTemp[e2], Program.Directory+Pfadteil)'"\\abcd\\Note Program.txt")'File.ReadLine(CheckFileDestination, e))
          TextWindow.Title = "AutoUpdater v" + AutoupdaterVersion + "   Downloaded: " + (LinkEnde-2) + "/" + HalbeZeilen + "   Installed: " + e2 + "/" + HalbeZeilen
          Program.Delay(1000)  
          
        Else
          TextWindow.WriteLine("Installing file: " + File.ReadLine(CheckFileDestination, e3))
          TextWindow.WriteLine(File.ReadLine(CheckFileDestination, e))
          UpdateFileInstallation[e2] = File.CopyFile(UpdateFileTemp[e2], File.ReadLine(CheckFileDestination, e))'Program.Directory+"\\abcd\\Note Program.txt")
          TextWindow.Title = "AutoUpdater v" + AutoupdaterVersion + "   Downloaded: " + (LinkEnde-2) + "/" + HalbeZeilen + "   Installed: " + e2 + "/" + HalbeZeilen
          Program.Delay(1000)
        EndIf  
      EndFor
    EndSub

    My textfile (I tried it with and without double slashes):

    1.0
    2
    http://sbautoupdater.npage.de/get_file.php?id=24521039&vnr=428469
    PD \\AutoUpdater - Test\\Note Program.txt

    It can't be the "ö" in the Program.Directory path, because it works if I don't read the rest of the path from a textfile.


    Mit freundlichen Grüßen Timo Greetings Timo


    • Edited by Timo Sö Saturday, August 24, 2013 10:37 AM
    Saturday, August 24, 2013 10:35 AM

Answers

  • Timo, the error is in the following line:

    UpdateFileInstallation[e2] = File.CopyFile(UpdateFileTemp[e2], Program.Directory+Pfadteil)

    ^^^^

    This e2 is 1 and should be   e (=3)   


    Jan [ WhTurner ] The Netherlands

    • Proposed as answer by Nonki Takahashi Wednesday, August 28, 2013 2:19 PM
    • Marked as answer by Timo Sö Saturday, September 14, 2013 3:50 PM
    Tuesday, August 27, 2013 2:11 PM
    Answerer

All replies

  • Timo,

    Your path has to include the diskcharacter  C:


    Jan [ WhTurner ] The Netherlands

    Saturday, August 24, 2013 10:49 AM
    Answerer
  • It does.

    The Program.Directory path includes it.


    Mit freundlichen Grüßen Timo Greetings Timo

    Saturday, August 24, 2013 10:54 AM
  • Timo,

    I created the following program:

    '' this program is called    copytest.sb
    FileIn= Program.Directory+"\copylist.txt"
    '''^^^^   this file contains:
    ''''''''      C:\z\p\basic\smbasic\vannet\tst\copyto.txt
    source=Program.Directory+"\copytest.sb"     ''this program
    TextWindow.WriteLine("source="+source)
    dest=File.ReadLine(FileIn,1)
    TextWindow.WriteLine("destination="+dest)
    File.CopyFile(source,dest)

    and the following textfile:  copylist.txt   with the contents as given in the program.

    This program works and copies itself ( source ) to the path with copyto.txt

    Try to solve your problem with such a test and when it works build it in your bigger program 


    Jan [ WhTurner ] The Netherlands

    Saturday, August 24, 2013 11:41 AM
    Answerer
  • I did this test. It worked.

    But in the code above it does not work.


    Mit freundlichen Grüßen Timo Greetings Timo

    Saturday, August 24, 2013 11:58 AM
  • Timo, did you work out how to d/load a text file using the Network object?
    Sunday, August 25, 2013 2:13 AM
  • Timo, did you work out how to d/load a text file using the Network object?
    Yes I did.

    Mit freundlichen Grüßen Timo Greetings Timo

    Sunday, August 25, 2013 10:56 AM
  • Timo, 

    I did some experimenting with your program.

    It seems that FileCopy does NOT work on a temporary file. If I use instead of 

    UpdateFileTemp[..] the name of a regular file on my disk, the FileCopy works. I then tried to read the contents of the temporaryfile into memory with File.Readcontents and then write this to a standard file with File.WriteContents, and use this file as the source with FileCopy IT WORKED.

    This was only for testing, you can probably find a shorter solution.

    EDIT: after 4 hours:

    The above is not right. The error is somewhere else.

    I deleted both the for loops, and removed all array use. So I only downloaded one file, and then Filecopy-ed the temp file and....

    IT WORKED. Try this first and then expand the program.

    Here is the smaller test program

    AutoupdaterVersion = "1.0"
    CheckFileDestination = Program.Directory + "\\Note Program3.txt"
    Zeilen = File.ReadLine(CheckFileDestination, 2)
    HalbeZeilen = Zeilen/2
    PfadStart = 2+HalbeZeilen+1
    LinkEnde = PfadStart-1
    GesamtZeilen = Zeilen+2
    a()
    
    Sub a
        UpdateFileLink = File.ReadLine(CheckFileDestination, 3) 'Link der herunterzuladenden Datei wird eingelesen
        TextWindow.WriteLine("Downloading file: " + UpdateFileLink)
        UpdateFileTemp = Network.DownloadFile(UpdateFileLink)  'Die Datei wird in ein temporäres Verzeichnis geladen
        TextWindow.WriteLine(UpdateFileTemp+"<<<") 
       ''TextWindow.Title = "AutoUpdater v" + AutoupdaterVersion + "   Downloaded: " + i2 + "/" + HalbeZeilen + "   Installed: " + i3 + "/" + HalbeZeilen
        Program.Delay(1000)
        If Text.StartsWith(File.ReadLine(CheckFileDestination, 4), "PD ") = "True" Then
          Pfadteil = Text.GetSubTextToEnd(File.ReadLine(CheckFileDestination, 4), 4)
          TextWindow.WriteLine(PfadTeil) 'DEBUG
          TextWindow.WriteLine(Program.Directory+Pfadteil) 'DEBUG
          TextWindow.WriteLine("Installing file: " + Pfadteil)
          UpdateFileInstallation = File.CopyFile(UpdateFileTemp, Program.Directory+Pfadteil)'"\\abcd\\Note Program.txt")'File.ReadLine(CheckFileDestination, e))
         '' TextWindow.Title = "AutoUpdater v" + AutoupdaterVersion + "   Downloaded: " + (LinkEnde-2) + "/" + HalbeZeilen + "   Installed: " + e2 + "/" + HalbeZeilen
          Program.Delay(1000)  
          
        EndIf  
        TextWindow.WriteLine(UpdateFileInstallation)
    EndSub


    Jan [ WhTurner ] The Netherlands




    Sunday, August 25, 2013 1:50 PM
    Answerer
  • Timo, the error is in the following line:

    UpdateFileInstallation[e2] = File.CopyFile(UpdateFileTemp[e2], Program.Directory+Pfadteil)

    ^^^^

    This e2 is 1 and should be   e (=3)   


    Jan [ WhTurner ] The Netherlands

    • Proposed as answer by Nonki Takahashi Wednesday, August 28, 2013 2:19 PM
    • Marked as answer by Timo Sö Saturday, September 14, 2013 3:50 PM
    Tuesday, August 27, 2013 2:11 PM
    Answerer
  • I am sorry for my very late answer.

    I tried what you say, and now everything works well. Thanks.


    Mit freundlichen Grüßen Timo Greetings Timo

    Saturday, September 14, 2013 3:50 PM