update file in the folder.

i have a folder in the GoogleDrive. Its named 'lgc'. In it, i have a file info. I know the ID of the folder, but i dont know the ID of 'info' text file in it. I want to UPDATE the content of 'info' file, Conditions to update:

  • I dont want to change file name or title, only wanting to change its contents.
  • I dont want to use File ID for 'info' file. Using search Query, that will only result file with name as 'info'.
  • So, How do i find file without id and How do i Update it? I looked Google Developers website. but please help me, i didnt understood it.

    tell me answer to following too: how can i do following?

  • Before Uploading a file, Check if any file with the same Title is present in Drive.
  • If present, delete present file and upload new file (Instead of Updating it)

  • Everything in Drive is keyed from the file ID, which is why you can end up multiple files sharing the same name. To modify content in Drive, you will have to at some stage work with the file ID, you cannot avoid that.

    You can search for a file by name (title = 'info' and [parentID] in parents), but you will still need that query to return the file ID so that you can then update.

    So your steps would be:

    1) files.list where q is: title = 'info' and [parentID for lgc] in parents 2) If you get results, do a files.delete for each file ID returned (you could get more than 1) 3) files.insert for your new info file.

    Some notes:

    Drive doesn't support what you are trying to do as an atomic operation, which means there are some edge cases you will need to handle if you have a) the potential for multiple applications operate on the same account or b) multiple users operating on the same folder or c) the potential for a user themselves to create a file called 'info' in that lgc folder.

    Step 1 may return more than a single file, so you should cater for that in step 2. Another 'info' file may be created between Step 1 and Step 3, so after step 3 you should run the files.list search again to confirm that only your new file exists.

    链接地址: http://www.djcxy.com/p/66440.html

    上一篇: 如何迭代SparseArray?

    下一篇: 更新文件夹中的文件。