BarretteKinder
Member
is there somthing to copy one folder (and all other folder and file in it) in another folder?
Dim MyList As List
Dim MyFile As String
Dim i as Short
File.MakeDir(File.DirRootExternal,"BarretteKinder2")
MyList.Initialize 'initialize list so it is ready for a new task
Dim MyFile As String
MyList=File.ListFiles(DBFilePath)
For i=0 To MyList.Size-1
MyFile=MyList.Get(i)
File.Copy(File.DirRootExternal & "/BarretteKinder1",MyFile,File.DirRootExternal & "/BarretteKinder2",MyFile)
Next
MyList=File.ListFiles(DBFilePath)
MyList=File.ListFiles(File.DirRootExternal & "/BarretteKinder1")
That doesn't work for me.The below code will copy the contents (files and subfolders) of a folder in your SDcard called: BarretteKinder1 to another folder in the SDcard called: BarretteKinder2
B4X:Dim MyList As List Dim MyFile As String Dim i as Short File.MakeDir(File.DirRootExternal,"BarretteKinder2") MyList.Initialize 'initialize list so it is ready for a new task Dim MyFile As String MyList=File.ListFiles(DBFilePath) For i=0 To MyList.Size-1 MyFile=MyList.Get(i) File.Copy(File.DirRootExternal & "/BarretteKinder1",MyFile,File.DirRootExternal & "/BarretteKinder2",MyFile) Next
sub Copydir (olddir, newdir)
make newdir
read all names in olddir
step through list of names:
if the name is a file
copy file from olddir to newdir
else
call copydir (olddir+name, newdir+name)
next
end sub
Dim MyList As List
Dim MyFile As String
Dim i As Int
Dim folder1, folder2 As String
folder1= "cmweb" :folder2="cmweb2"
File.MakeDir(File.DirRootExternal,folder1)
File.MakeDir(File.DirRootExternal,folder2)
MyList.Initialize
Dim MyFile As String
MyList=File.ListFiles(File.DirRootExternal & "/" & folder1)
For i=0 To MyList.Size-1
MyFile=MyList.Get(i)
If File.IsDirectory(File.DirRootExternal & "/" & folder1,MyFile)=True Then
File.MakeDir(File.DirRootExternal,folder2 & "/" & MyFile)
Else
File.Copy(File.DirRootExternal & "/" & folder1,MyFile, File.DirRootExternal & "/" & folder2,MyFile)
End If
Next
Sub CopyDir (OldRoot, NewRoot, FolderName As String)
Dim MyList As List
Dim MyFile As String
Dim i As Int
File.MakeDir(NewRoot,FolderName)
MyList.Initialize
Dim MyFile As String
MyList=File.ListFiles(OldRoot&"/"&FolderName)
For i=0 To MyList.Size-1
MyFile=MyList.Get(i)
If File.IsDirectory(OldRoot&"/"&FolderName,MyFile)=True Then
CopyDir(OldRoot & "/" & FolderName, NewRoot & "/" & FolderName, MyFile, )
Else
File.Copy(OldRoot&"/"&FolderName,MyFile, NewRoot&"/"&FolderName,MyFile)
End If
Next
End Sub
This sub should work - although I have not tested it
CopyDir(OldRoot & "/" & FolderName, NewRoot & "/" & FolderName, MyFile, )
Sub CopyDir (OldRoot, NewRoot, OldFolderName, NewFolderName As String)
Dim MyList As List
Dim MyFile As String
Dim i As Int
File.MakeDir(NewRoot,NewFolderName)
MyList.Initialize
Dim MyFile As String
MyList=File.ListFiles(OldRoot&"/"& OldFolderName)
If MyList.Size > 0 Then
For i=0 To MyList.Size-1
MyFile=MyList.Get(i)
If File.IsDirectory(OldRoot&"/"& OldFolderName,MyFile)=True Then
CopyDir(OldRoot & "/" & OldFolderName, NewRoot & "/" & NewFolderName, MyFile, MyFile)
Else
File.Copy(OldRoot&"/"&OldFolderName,MyFile, NewRoot&"/"& NewFolderName,MyFile)
End If
Next
End If
End Sub
File.MakeDir (File.DirDefaultExternal, "old")
File.MakeDir (File.DirDefaultExternal & "/old", "empty")
File.MakeDir (File.DirDefaultExternal & "/old", "morefiles")
File.MakeDir (File.DirDefaultExternal & "/old/morefiles", "somemore")
File.MakeDir (File.DirDefaultExternal & "/old/morefiles", "emptyagain")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old", "file1")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old", "file2")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old", "file3")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old/morefiles", "file4")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old/morefiles", "file5")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old/morefiles", "file6")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old/morefiles/somemore", "file7")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old/morefiles/somemore", "file8")
File.Copy (File.DirAssets, "cona.png", File.DirDefaultExternal & "/old/morefiles/somemore", "file9")
CopyDir (File.DirDefaultExternal, File.DirDefaultExternal, "old", "new")
Hello kickaha,
We were posting at the same time so I deleted mine as it would be confusing. I'll be glad to test it! Thanks! I also look forward to learning something because kickaha has taught me so much!!:icon_clap:
CopyDir (File.DirRootExternal, File.DirRootExternal, "ECA", "ECA2" )
@Margret: I hope you or someonme else get a chance to test Kickaha code, because I tested and still get an IndexOutofBouds error.
The OldFolderName has several files and only one Subfolder. I tested with the subfolder empty. It returned the error. I inserted a file in the subfolder so it is not empty and got the error again. It is not essential that I find a solution to this.B4X:CopyDir (File.DirRootExternal, File.DirRootExternal, "ECA", "ECA2" )
MyFile=MyList.Get(i)