let say the source folder is Folder A. The target folder is Folder B.
Each time period (maybe 1 day), delete folder B and I use programming copy Folder A to Folder B using recursion.
I am doing this since this is the most simple way.
But this method is stupid, since each time the folder B is deleted.
Is there any way we just alter the target folder a little bit if there is only a minor change in folder A?
If I understand you correctly you have a main folder A with some files in it. These files may or may change over the course of the day. Once a day you want to backup everything that is in folder A to folder B.
Your current method off attack to solve this issue is to simply delete folder B every day and copy everything from A into B.
I agree this is the simplest option and I really don't see any issue with it assuming that is that there are not a large number of files or large files which can be time consuming to copy.
check for changes.
What you could do when you request the files in Folder A is check the modifiedTime on the file. It should show you the last time the file was changed. If the file hasnt been changed since the last time you did your backup then there is no reason to copy it to folder b. If it has changed then you delete that file from folder B and copy the new one in.
"modifiedTime": "2021-08-13T06:39:56.708Z",
Now this does not take into account new files which have been created in folder A nor does it take into account files which may have been deleted from folder A.
For that you will need to do a file.list and compare what you have currently in A and b. If A has files that B doesn't well then they are new files and you need to copy them in if A is missing some files that appear in B well then they were deleted you should delete them from B.
Would i bother.
In my opinion unless we are taking about more then say 200 files or the files are bigger then 10 mb I don't think i would bother changing what you have now. While i agree checking would be a more elegant solution the question comes into play is it worth it in the end if you are only copying 10 files.
Related
Is there a symlink equivalent for IPFS's Mutable File System? For example, if I have a file:
/source/file.txt
and I copy it another folder:
ipfs files cp /source/file.txt /reference/file.txt
the two files will refer to the same object. If I make a change to /source/file.txt the copy in /reference/file.txt will still point to the old version. Is there a good way to make it point to the current version of the file in /source/?
I could keep track of all the copies and update them whenever I change the original, but that doesn't sound fun. I could also store the string "/source/file.txt" in /reference/file.txt and manually dereference each time I want to access the file. Better, but still cumbersome. Are there any other options?
For the time being, there is no support for symnlinks in MFS: you need to track and update them manually in userland. Current MFS implementation uses immutable identifiers (CID) and each directory's CID is based on hashes of its children, so storing string in a file sounds like the most optimal way, as it does not trigger DAG recalculation every time you update the target file.
For example, I'm going to upload a file scenery.jpg to /images/2020/03/18/ directory, if I upload to OneDrive, the upload url going to be like this:
https://graph.microsoft.com/v1.0/me/drive/root:/images/2020/03/18/scenery.jpg
I don't have to know if the images folder, the 2020, 03 and 18 folder exists or not, OneDrive will auto create it recursively, acting like Object-based Storage.
But now, I'm going to upload it to GoogleDrive and GoogleDrive seems can't create folders recursively(as far as I know, see Create and populate folders), now I have 2 questions:
1、Is that I have to check if these folders exists one by one to make sure if I have to create these folders?
/images/
/images/2020/
/images/2020/03/
/images/2020/03/18/
2、If none of above folder exists, is that I have to create these four folders one by one(means request api four times)?
Anyone who did this before? I hope what I assume is wrong, because it's too complicated to do it in this way.
Unfortunately you are correct
Google handles file and folder hierarchy in a different way and indeed the only way create / list nested files and folders is to iterate recursively.
Also, if you want to know if a file / folder already exists with the method Files:get, you need to know the file / folder ID, rather than just the name. If you do not know the ID, than you need to list all files on your drive / (unless you specify a certain folder as the parent folder, e.g. '1234567' in parents with the query parameter q).
The same applies for creation. If you create a folder which you want to be a subfolder of a different parent folder - you also need to create the parent folder.
However, it is not as complicated as you may think.
Here is one of many available samples of how to list the contents of all subfolders and subfolders of subfolders dynamically - in your case you would just need to add the condition to create a certain folder if it is not contained in the list.
You would need to take some time to study the working principle of Drive API, however once you get an understanding it is not complicated.
Really, there is no way to move a file or folder using the DriveApp class?
From what I could gather on the docs and on the StackOverflow answered questions all proposed implementations seem to copy the file to another location and then delete the original file. That would result in at least two problems:
File/folder having a different folderId on the destination;
File/folder being duplicated and stored indefinitely on Google Vault by retention policy.
I must be doing something wrong. Why is there not a method to simply move the file/folder to another destination (as provided by the Drive Web UI)?
Thanks,
When it comes to moving files with DriveApp, you need to work from the Folder rather than the File.
Open the folder you want to move the file to and use the "addFile(file)" method to add the file to that folder, then open the folder you want to move the file from and use "removeFile(file)" to remove it.
This might seem a bit clunky but it's actually possible to have a file in more than one folder at a time on Drive. The folders are really just labels. When considering a file that is already in multiple folders, the meaning of "moving" it to a new folder is kind of ambiguous, it's really a matter of adding/removing it from folders.
Add:
https://developers.google.com/apps-script/reference/drive/folder#addfilechild
Remove:
https://developers.google.com/apps-script/reference/drive/folder#removeFile(File)
Stumbled across this post (two years & 6 months later) and just wanted to point out that its now possible to do this:
DriveApp.getFileById(myFileId).moveTo(DriveApp.getFolderById(myTargetFolderId));
I want to save all the files of a specific source folder in chrome to a local folder, I found this but it seems can't do the job, I know I could save the file one by one, but since there are various files, mistake could happen and it's not boring to save one by one , so I want to know is there any way that I could save a folder to a local folder?
Thanks
I have a folder that is static with a daily txt file that goes into the folder. The file name is the date. If the file name has the same name every day, everything works. Is there a way I can have my script pull any txt file in the folder? (Note, file comes in, get's processed and then I have an automatic transfer that moves the file after it has been inserted to a processed folder). So there will only be one file at a time in the folder. I hope that makes sense.
Here is the script for the bulk insert:
Bulk Insert Mydata.dbo.cust_adj
From 'C:\MyData\FlatFiles\UnprocessedAdjReport\importformat.txt'
With
(
FieldTerminator= '|',
Rowterminator= '\n'
)
Go
(I've got this saved as a stored procedure btw)
So "importformat" is just the name I used while setting up my scripts, going forward it will be in bb-yyyy-mmdd-hhmmnnnn.txt, as soon as the file is inserted, I move the file from the unprocessed folder to the processed folder. There will only be the one file each day.
If anyone has any advice or assistance with this, I would greatly appreciate it.
See the link it may be what you are looking for:
http://www.kodyaz.com/articles/how-to-extract-filename-from-path-using-sql-functions.aspx
Or
http://sqljourney.wordpress.com/2010/06/08/get-list-of-files-from-a-windows-directory-to-sql-server/
Or maybe
http://www.codeproject.com/Articles/38850/An-Easy-Way-to-Get-a-File-Name-or-a-File-Extension
HTH