copy file not working

ilan

Expert
Licensed User
Longtime User
hi

i am trying to copy a file but i get an error thats its not existing

but it exist !!

what could be my mistake???

this is how i try it

B4X:
If File.Exists (File.DirInternal, "01.txt") Then
Msgbox("exist","")
File.Copy(File.DirInternal, "01.txt", File.DirInternal & savepos,"01.txt")
End If


Picture.png



seems like he try to copy from another directory File.DirInternal/files1 -->> from where came this directory? /01.txt ...

thanx
 

ilan

Expert
Licensed User
Longtime User
thanx for your reply

but he find the file thats not the problem i know that he find the file because i get the massage box but then when he start copy i get the error

what could it be??

maybe i cannot copy from the internal directory?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i am using numbers

in this case its 0

could that be the problem?

(wie kann ich am besten den ganzen Verzeichnis kopieren ohne die Unterverzeichnise nur die Datein, ich moechte in mein Program ein Backup Funktion machen und alle Datein speichere ich im File Internal Verzeichnis
und ich moechte jetzt ein Verzeichnis ersten in File Internal und dorthin alle Datein kopieren, dann wenn ich wieder herstellen moechte dann alle Datein von backup Verzeichnis wieder ins File Internal kopieren, danke fuer deine Hilfe)

ps.: sorry fuer mein Deutsch ist etwas eingerosttet :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I think the problem is this:
File.DirInternal & savepos,"01.txt"
You are trying to add a number to the DirInternal directory which is not possible. I think that you want to create a subdirectory.
If yes you must first define the subdirectory before you can access it.
Or perhaps try this, I don't know if the system creates a directory if it doesn't exist.
File.DirInternal & "/" & savepos,"01.txt"

Best regards.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
hi klaus

i am creating the directory before i try to copy the files
maybe as you allready said that numbers wont work as directory
i will try to add another directory name and try to copy my files

but i dont understand why the error massage says that he cannot find the files
in my file.dirinternal ??

seems like he cannot get the files i want to copy

can you post a simple copy code sample that copies all files in a directory without subdirectories only files?

thanx
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I don't really understand why you want to copy files from DirInternal to a subfolder of DirInternal.
DirInternal is a folder belonging to the program, no other program can access it.
I don't have a routine out of the box.
I would need, like you, to write one.
You have the function File.ListFiles(TheGivenDirectory) that lists all files and subdirectories in TheGivenDirectory.
Then you can check if the items in the list are directories or files with File.IsDirectory(Dir, Filename).

Best regards.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
I want to make a backup function in my program and all file i
Saved in file.internal and i would like ti create a subfolder in
It and copy all files from interbal to it
Then when j would like ti restore copy back from subfolder
To dir internal
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try this routine :
B4X:
'Copies all files from SourceDir to DestinationDir
Sub CopyFiles(SourceDir As String, DestinationDir As String)
    Dim lst As List
    Dim FileName As String
    
    lst = File.ListFiles(SourceDir)
    For i = 0 To lst.Size - 1
        FileName = lst.Get(i)
        If File.IsDirectory(SourceDir, FileName) = False Then
            File.Copy(SourceDir, FileName, DestinationDir, FileName)
        End If
    Next
End Sub
Best regards.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Thanks klaus

It works,!

I changed the folder name to string and use theroutine you post
And it works


Thanks again
 
Upvote 0
Top