This question already has answers here:
Search for files inside of a folder using drive api
(2 answers)
Is there a way in google script to access files inside a folder through a shortcut to the folder by folder name?
(1 answer)
Finding subfolders within parent folder
(2 answers)
Closed 3 months ago.
This post was edited and submitted for review 3 months ago and failed to reopen the post:
Original close reason(s) were not resolved
I got a questions regarding the DriveApp.folders() function for the google Scripts. I just implemented a script which add a description to all my files, that the last change date will get updated. For this I used the DriveApp.folders() with .getfiles(). Now my Problem: this function access all folders, even the shared folders, but it should only access the Folders in My Drive? How can I handle this?
I tried already the .getOwner() function, but with this i get 'DriveUser' as Answer with some shared drive folders.
I tried also to get the access by .getFolderbyID() but there is no ID for my drive.
Here is my code:
function writeDescription() {
var folder = DriveApp.getFolders();
var count = 0;
while (folder.hasNext()){
var ordner = folder.next();
var files = ordner.getFiles();
Logger.log(ordner.getName())
//Logger.log(files)
while (files.hasNext()){
var file = files.next();
count = count +1;
file.setDescription(" ");
//Logger.log(file.getName());
}
}
Logger.log(count);
}
use https://developers.google.com/apps-script/reference/drive/folder#getOwner() and compare to your email to get only the ones you own.
Related
This question already has answers here:
XMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' header
(11 answers)
Closed 2 years ago.
This the working script.
$.getJSON('http://time.jsontest.com', function(data) {
var text = `Date: ${data.date}<br>
Time: ${data.time}<br>
Unix time: ${data.milliseconds_since_epoch}`
$(".mypanel").html(text);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="mypanel"></div>
In the above script I replaced the URL as http://abacusshopee.biz/COMPUTERS/test.json then the Code is not working.
The contents of the JSON file as follows.
{
"date": "09-02-2020",
"milliseconds_since_epoch": 1599029414853,
"time": "06:50:14 AM"
}
I used same json files for fetching data. Both the files contains. same data.
My problem is that when test with the first script, it is working. But when try with the second one (using 'http://abacusshopee.biz/COMPUTERS/test.json') the script not working.
I have solved this issue. It is a CORS issue. I have changed the url as 'https://cors-anywhere.herokuapp.com/http://abacusshopee.biz/COMPUTERS/test.json'. The test.json file opened via proxy link https://cors-anywhere.herokuapp.com.
Thanks for comments.
This question already has answers here:
Delete Folder from Firebase Storage using Google Cloud Storage
(2 answers)
Closed 5 years ago.
I want to delete a Firebase Storage folder and all its contents using node.js / Firebase Admin SDK but I'm not able to.
A similar question was asked in the google group below about a year ago and I'm wondering if there is a solution now:
https://groups.google.com/forum/#!topic/firebase-talk/aG7GSR7kVtw
I am able to delete a single file using node.js example below:
https://mzmuse.com/blog/how-to-upload-to-firebase-storage-in-node
But I'm not able to delete a folder and all it's contents.
Any ideas? Am I missing something?
Here's the code I'm using
const keyFilename="path/to/my/private.json";
const projectId = "myprojectid";
const bucketName = `${projectId}.appspot.com`;
const gcs = require('#google-cloud/storage')({
projectId,
keyFilename
});
const bucket = gcs.bucket(bucketName);
THIS WORKS FINE - Deleting a single file
const deleteFile = 'users/user1/folder1/IMG_1.JPG'
const gcFile = bucket.file(deleteFile);
gcFile.delete((err,res)=>console.log(err||res));
THIS DOES NOT WORK - Deleting the folder and contents
const deleteFolder = 'users/user1/'
const gcFolder = bucket.file(deleteFolder);
gcFolder.delete((err,res)=>console.log(err||res));
--
THIS IS NOT A DUPE AS MARKED BY SOME MEMBERS
My question is specific to node.js and the answer given is for Java.
UPDATE
I found this a page in google cloud site where they show a way to delete all files under a directory (folder)
https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/0.56.0/storage/bucket?method=deleteFiles
bucket.deleteFiles({
prefix: 'images/'
}, function(err) {
if (!err) {
// All files in the `images` directory have been deleted.
}
});
But I'm still not able to delete the folder itself
From this post:
You can delete only the whole bucket, but you cannot delete a folder
in a bucket.
Use GcsService to delete files or folders.
String bucketName = "bucketname.appspot.com";
GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
gcsService.delete(new GcsFilename(bucketName, "test"));
This question already has answers here:
blueImp/jquery file upload - How do I get the error message if the file type was not accepted?
(9 answers)
Closed 3 years ago.
I am using jQuery File Upload Plugin 5.21 to upload files to my site. My need is to show error message instantly when a file type not like image is added(by checking file extension). how to use built in function to check this operation like _onSend _beforeSend but not aware of using it.
(If possible can show a demo?).Thankx in advance
You can use below code.
JavaScript
add: function (e, data) {
var goUpload = true;
var uploadFile = data.files[0];
if (!(/\.(gif|jpg|jpeg|tiff|png)$/i).test(uploadFile.name)) {
common.notifyError('You must select an image file or your message.......');
goUpload = false;
}if (goUpload == true) {
data.submit();
}
},
This question already has answers here:
How do i get the full path of the file in Firefox
(1 answer)
How to get the file path from HTML input form in Firefox 3
(8 answers)
Closed 8 years ago.
So far I've been able to get only the file names from the browse button by using just jQuery and HTML file form. Here is my fiddle: http://jsfiddle.net/p42Wv/2/
MY ATTEMPT
$("#file").bind("change", function() {
var elem = document.getElementById("file");
var names = [];
for (var i = 0; i < elem.files.length; ++ i) {
names.push(elem.files[i].name);
}
var names2 = names.join('\n');
$("#filename").val( names2 );
});
I get the file names as I'm supposed to BUT how do i get the Folder Names as well as the file names when I select a mixed list of files and folders in the "Browse" button?
EDIT:
NOTE: I'm looking for Folder Name and NOT the Folder Path.
I've seen website such as Google Drive that lets user's select a WHOLE folder to upload. Isn't the mere extraction of folder names such an issue? If not, how does Google Drive for instance, access the subfiles of a folder and upload?
Thanks a lot,
John
This question already has answers here:
How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?
(14 answers)
Closed 9 years ago.
I have created <input type="file" name="files" id="fld1" webkitdirectory > in an html file.
i can get the files using
var imageFiles = document.getElementById("fld1"),
filesLength = imageFiles.files.length;
for (var i = 0; i < filesLength; i++) {
alert(imageFiles.files[i].name);
}
How can i get the full path of the directory selected in javascript . please help
I want to show all the image files present in any folder using jquery slider. i can get the name of the files present in that folder but i cannot get the full path of the folder. how can i get it.
i have done this to get the file path but it only worked in IE
<script language="JavaScript">
function GetDirectory() {
strFile = document.MyForm.MyFile.value;
intPos = strFile.lastIndexOf("\\");
strDirectory = strFile.substring(0, intPos);
alert(strFile + '\n\n' + strDirectory);
return false;
}
</script>
For obvious security reasons you cannot do that. Browsers won't allow you to access and explore the file system of the client computers using javascript. Some browsers will simply return some fake path to the file.
Check File API documentation, the File section gives details about the File object.
Quoting from the doc:
The name of the file; on getting, this must return the name of the
file as a string. There are numerous file name variations on different
systems; this is merely the name of the file, without path
information. On getting, if user agents cannot make this information
available, they must return the empty string.