Created
September 6, 2011 23:03
-
-
Save jonalter/1199248 to your computer and use it in GitHub Desktop.
Android/iOS: copy folder with contents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var win = Ti.UI.createWindow({ | |
| backgroundColor : '#fff', | |
| layout : 'vertical' | |
| }); | |
| var testButton = Ti.UI.createButton({ | |
| title : "Copy Folder", | |
| top : 20, | |
| height : 50, | |
| width : 250, | |
| }); | |
| testButton.addEventListener('click', function(e) { | |
| var folderName = "data"; | |
| var srcDataDir = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, folderName); | |
| var destDataDir = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, folderName); | |
| destDataDir.createDirectory(); | |
| var files = srcDataDir.getDirectoryListing(); | |
| Ti.API.info('ALL FILES ' + files); | |
| var qty = files.length; | |
| for(var i = 0; i < qty; i++) { | |
| Ti.API.info('ROW [' + files[i]+']'); | |
| var srcFile = Ti.Filesystem.getFile(srcDataDir.nativePath, files[i]); | |
| var destFile = Ti.Filesystem.getFile(destDataDir.nativePath, files[i]); | |
| destFile.write(srcFile.read()); | |
| Ti.API.info( "destFile: "+destFile.read() ); | |
| } | |
| Ti.API.debug("srcDataDir: " + srcDataDir.getDirectoryListing() ); | |
| Ti.API.debug("destDataDir: " + destDataDir.getDirectoryListing() ); | |
| }); | |
| win.add(testButton); | |
| win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment