Buy the full source code of application here:
https://procodestore.com/index.php/product/google-apps-script-deleting-google-drive-files-in-folder-example/
Show More Show Less View Video Transcript
0:00
Hi friends, today in this tutorial I
0:02
will be telling you that how to delete
0:04
files which are stored inside your
0:06
Google drive in specific folder. So this
0:08
is example. So now inside Google app
0:11
appcript I am writing my code. First of
0:13
all we need to get the folder in the
0:16
Google drive. So we will be using drive
0:18
app dot get folder by id. So here we
0:22
just need to provide the ID of the
0:23
folder. So in order to get the ID right
0:25
click on the folder get sharable link
0:27
and now open this link in the browser
0:31
and this is the ID you can see that ID
0:33
is equal to and just copy this text here
0:36
and you just need to provide the ID like
0:38
this inside double quotes and now we
0:40
have successfully got the folder in
0:42
order to get the files we will be
0:44
declaring a files variable and we will
0:46
be invoking a method folder dot get
0:49
files this is a method so basically it
0:51
will return the files in an array. Okay.
0:54
And now we just need to iterate it. So
0:56
we will be using the while loop. And
0:58
inside this we will write here files dot
1:00
has next. So it will return a boolean
1:02
value if any kind of file is present
1:04
inside this folder. And now we just need
1:06
to write a very simple line of code
1:09
which will be files dot next dot set
1:14
trashed. So basically this is a here we
1:17
just need to pass true the boolean
1:18
value. That's it. And now it will be
1:21
deleting all the files. Once I run this
1:23
function, I need to first of all give it
1:25
name to it. Let's suppose I give it a
1:27
name of delete. Click on okay. And now
1:30
it will ask for the permissions. First
1:31
of all, if you run this, so if I run
1:33
this code here,
1:36
so it is saving the file code. So just
1:38
wait, it will be given just uh uh give
1:42
the permissions first of all login onto
1:45
your account, Google account and uh then
1:48
you just need to click on advance. Go to
1:51
delete. Here you can see that and grant
1:53
the permissions
1:56
allow it
1:59
and now it will run the function and you
2:01
will see that all these files will be
2:03
deleted. So just wait you will see that
2:05
guys all the files have been deleted in
2:07
this folder images. So in this easy way
2:09
you can just delete all the files which
2:11
are stored inside a folder in Google
2:13
drive using Google appcript. So
2:15
basically this is not mandatory. You
2:17
have to first of all look onto the
2:19
folder. This can be crucial content of
2:22
yours. So make sure that you need to
2:24
delete all the files before deleting it.
2:26
So in this way, this is a line of
2:28
JavaScript code that is necessary in
2:30
order to delete files stored in Google
2:31
Drive. So, thanks very much for watching
2:32
this
