I'm trying to delete a folder in GCS with the following code, I need to delete a folder inside a folder with all of it's containing data.
Storage storage = CredentialsProvider.getStorageService();
Page<Blob> blobs = storage.list("pdf",
Storage.BlobListOption.prefix("parent_folder/folder_to_delete"),
Storage.BlobListOption.currentDirectory());
for (Blob blob : blobs.iterateAll()) {
System.out.println(blob.getName());
storage.delete(blob.getBlobId());
}
This code prints all the folders within the folder_to_delete folder but not removing anything. Do we have other approach to delete a folder?
Because folders does not exist, you can't delete a folder.
A folder is a human representation of path separated by /. Remove all the object in the same path (i.e. folder) the folder will disappear.
More detail here on the "folders"
Related
Is there any way to download a folder : all files within the folder and subfolders in Liferay 6.2 without using a loop through all files existing in the folder ?
I need to do it programmatically.
Example :
Folder to download "XFolder"
XFolder
- SubFolder1
- File11
- File12
- SubFolder2
- File21
- File22
- File1
- File2
When choosing to download XFolder, the system searches the folder in document and media and saves all the folder content in a .zip file in disk.
The content should have the same structure above.
Thank you for your help.
You can try to use the "treePath" value of folder and entry to figure out the files but you still will require some looping.
You will probably need dynamic queries for this.
the algorithm should go something like this.
Find out ID of your folder
Look through the treePath property of the Folder table and get a list of all paths that you are interested in.
get all folder ids
loop through all the folders that you are interested in and load their respective files. (Probably you could also do a query that would collect it all in one go)
I want to create a hidden folder in user's Google drive root directory and then want to insert some text files in that folder and later want to retrieve that files. I tried the quick guide and files are uploading fine but in the root directory and files are visible to user. From here I know how to create an empty folder. . But from here I do not understand how to use that code to insert the file in a particular folder.
So my Question is how to create hidden folder and perform CURD operations on files using drive API.
You're looking for the appdata folder. See here:
https://developers.google.com/drive/appdata
I want to delete a file in assets folder in run-time. I have a database file in assets folder that copies to data folder at run-time but after installing my app the size of app become twice as large (assets + data folder)!
How I can delete database file from assets folder to avoid this?
You can't delete a file at runtime that was delivered with your App.
See this discussion about it:
How to remove a file in assets at run time?
The whole content of your APK is read only and can not be modified
in addition to the above answer, one thing you can do is preferExternalStorage in manifest..which will help
I am having problems listing assets in my apk file, my aim is to be able to get the direct path of one of my assets and pass it to native code using JNI
1. I have added a file to the assets folder of my project
2. I have verified that the file exist in the '/assets' folder of the apk file resulting of compilation of my project
3. at the 'onCreate' function of my Activity I do the following:
AssetManager am = this.getApplicationContext().getAssets();
String strAssets[] = am.list("/assets");
4. strAssets.length is always zero
5. I was getting the same for "./assets" and "assets"
What am I doing wrong here? why can't I list the available assets?
Any help will be appreciated.
~Nadav at sophin
am.list("/assets") lookes for a folder called 'assets' within your assets folder. Just use am.list("") to get all files.
The argument to the list method is the path within the assets folder. if it's at the root, shouldn't you get results from either an empty string or a single slash?
AssetManager.list(String path)
After searching 1 hour i do not found any solution to my problem.
I want to move a file from sdcard to assets folder and also overwrite the existing file in assets folder (both file are sqlite database have same name with just a little difference in data )
??
Actually, The behaviour of the android .apk file is read only so the directory structure which are in that apk file follows the same, So no one can write this files or make changes on that at runtime,that's why You can't make a changes in /asset folder at runtime. you can read file from it (means copy files which are available in asset to any internal storage or /sdcard but not write it to vice-versa)
Its apply on all the directories which are build in .apk files. As per docs.
Assets folder are not Writable it is only readable so you cant copy from sdcard to assets, yes you can copy from assets to sdcard
If you want other apps not to access your database then what you can do is
Download the database from website. create a temp database also in app directory.
getDatabasePath() this will give you the path of the dummy database you have created now replace this with the one you downloaded.
PS.: User and apps having root access still able to access it and you cant do anything in that scenario