I'm trying to build a small electron app. It gets a file/files from the user, then copies them to a specific folder, and adds all the info about that file to a database.
const fs = require('fs-extra')
//sample 2 file entry
files = {"0":{"name":"File1.png","path":"A:\\User Folders\\Desktop\\File1.png"},"1":{"name":"File2.jpg","path":"A:\\User Folders\\Desktop\\File2.jpg"},"length":2}
window.$ = window.jQuery = require('jquery');
jQuery.each(files, function(file) {
//this is just one of many variables I need
currentfile = files[file].path
fs.copy(currentfile, "./files/"+"."+files[file].name, function (err) {
if (err) {
console.log(err)
} else {
console.log(currentfile);
//I expect this to log file1 then file2 so I can submit it to my database,
//but it always logs file2
}
})
});
It works fine for one file at a time, but when I try to handle more than one it doesn't work as I expect it (copy a file, update the DOM, copy next file, updates DOM, etc).