diff --git a/apps/toolbox/src/pages/fs-helper.ts b/apps/toolbox/src/pages/fs-helper.ts index 8924d5852..a4ca20d51 100644 --- a/apps/toolbox/src/pages/fs-helper.ts +++ b/apps/toolbox/src/pages/fs-helper.ts @@ -109,7 +109,8 @@ export function pickFile() { const file = args.intent.getData().toString(); //const file = File.fromPath(args.intent.getData().toString()); //console.log(file); - readFile(file); + //readFile(file); + copyFile(file); } }); const Intent = android.content.Intent; @@ -172,6 +173,41 @@ function saveFile(selected, readSync) { console.log('==== SAVE END ========='); } +function copyFile(file) { + const picked = File.fromPath(file); + const ext = picked.extension; + const name = picked.name.replace(`.${ext}`, ''); + const tempCopy = File.fromPath(path.join(knownFolders.temp().path, `${name}-copy.${ext}`)); + + // const done = picked + // .copySync(tempCopy.path); + // console.log('done: ' + done + '\n' + 'Original path: ' + picked.path + '\n' + 'Copied to: ' + tempCopy.path + '\n' + 'Original size: ' + picked.size + '\n' + 'Copy size: ' + tempCopy.size + '\n'); + + picked + .copy(tempCopy.path) + .then((done) => { + console.log('done: ' + done + '\n' + 'Original path: ' + picked.path + '\n' + 'Copied to: ' + tempCopy.path + '\n' + 'Original size: ' + picked.size + '\n' + 'Copy size: ' + tempCopy.size + '\n'); + }) + .catch((error) => { + console.log(error); + }); +} + +export function copyTest() { + const now = Date.now(); + const tempFile = File.fromPath(path.join(knownFolders.temp().path, `${now}.txt`)); + tempFile.writeTextSync('Hello World: ' + now); + const tempCopy = File.fromPath(path.join(knownFolders.temp().path, `${now}-copy.txt`)); + tempFile + .copy(tempCopy.path) + .then((done) => { + console.log('done: ' + done + '\n' + 'Original path: ' + tempFile.path + '\n' + 'Copied to: ' + tempCopy.path + '\n' + 'Original size: ' + tempFile.size + '\n' + 'Copy size: ' + tempCopy.size + '\n'); + }) + .catch((error) => { + console.log(error); + }); +} + function getFileNameFromContent(content: string) { const file = getFileAccess().getFile(content); return decodeURIComponent(file.name).split('/').pop().toLowerCase(); diff --git a/apps/toolbox/src/pages/fs-helper.xml b/apps/toolbox/src/pages/fs-helper.xml index 000d09a5d..7b0970cd1 100644 --- a/apps/toolbox/src/pages/fs-helper.xml +++ b/apps/toolbox/src/pages/fs-helper.xml @@ -4,5 +4,6 @@