copy file not working

ilan

Expert
Licensed 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




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

thanx
 

ilan

Expert
Licensed 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 :)
 

klaus

Expert
Licensed 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.
 

ilan

Expert
Licensed 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
 

klaus

Expert
Licensed 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.
 

klaus

Expert
Licensed 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.
 
Top