WEBVTT 00:06.180 --> 00:12.150 In this video you're going to get introduced to more features which you can use inside the FSA module 00:12.330 --> 00:13.380 of note. 00:13.380 --> 00:16.040 So let's start with deleting a file. 00:16.200 --> 00:24.960 So I'm going to create a new file and call it file dot texts so to delete this file the asynchronous 00:24.960 --> 00:35.510 way you can use the unlink method of efforts so you just pass the path of the file. 00:35.690 --> 00:44.420 So in our case it's going to be file dot text and then you pass the callback. 00:44.510 --> 00:45.500 So for example 00:50.400 --> 00:57.460 we can just log the error if it exists so let's check if the error exists first. 01:01.360 --> 01:03.790 In that case we're going to log 01:07.930 --> 01:10.710 the error. 01:11.190 --> 01:15.960 Otherwise we will just log something like 01:19.790 --> 01:21.380 file text has been deleted 01:25.670 --> 01:29.810 it's defined the efforts constants of the very top 01:34.440 --> 01:35.350 and let's try. 01:35.370 --> 01:35.810 Okay. 01:41.430 --> 01:41.760 Okay. 01:41.790 --> 01:42.170 So. 01:42.180 --> 01:45.830 And our file has been deleted successfully. 01:45.840 --> 01:47.430 Okay perfect. 01:47.430 --> 01:52.970 Now let's check how we can copy a file. 01:53.460 --> 01:53.940 So 01:56.680 --> 02:03.360 the methods you use is going to be a copy file if you want to do this asynchronously. 02:03.800 --> 02:10.300 No you pass the path of the file to copy file. 02:10.700 --> 02:14.410 So let's say that we want to copy Jupiter. 02:15.220 --> 02:28.650 So I'm going to paste this bit of a top cards to be able to use the variables if we need them. 02:28.710 --> 02:33.220 So that's the path of the file to copy. 02:33.390 --> 02:39.150 And then you pass the new path or the path of the new file. 02:39.660 --> 02:43.680 So let's just call it Jupiter. 02:43.680 --> 02:52.100 Copy both texts and then we're going to pass a callback since we're using the asynchronous way 02:58.810 --> 03:03.970 so we just copy this and say That's the 03:09.480 --> 03:10.090 file. 03:10.170 --> 03:37.050 Jupiter has been copied successfully. 03:37.200 --> 03:40.640 We need only one declaration of efforts. 03:40.860 --> 03:43.710 So we destroy our code and see how it goes. 03:43.710 --> 03:48.300 So by the way we're gonna get an error because we're trying to delete that file. 03:48.360 --> 03:58.290 So I'm just gonna come on this will now and let's go ahead and we have just created a copy of Jupiter 04:00.760 --> 04:03.270 perfect. 04:03.930 --> 04:04.290 OK. 04:04.320 --> 04:11.310 So now let's move to something else. 04:11.840 --> 04:18.410 So we want to create a directory or before doing that. 04:18.470 --> 04:26.090 Let's try to copy our file again and create a new file named Jupiter. 04:26.190 --> 04:27.610 Copy as well. 04:27.600 --> 04:36.580 So if you try that's you can see that the file has been copied successfully and by the way we have just 04:36.940 --> 04:40.030 overridden the existing file. 04:40.200 --> 04:48.780 So if you want to check that you can just write some text here run the command again and you'll see 04:48.780 --> 04:50.780 that the file has been overwritten. 04:51.390 --> 04:57.600 So if you want to avoid that you can add a flag to the method copy file. 04:58.380 --> 05:00.270 So there are many constants you can use 05:03.340 --> 05:11.590 here and you can search the list of constants by googling FS Constance so the constant to use to avoid 05:11.650 --> 05:24.850 overriding an existing file is F as Dot constants dot copy file underscore X.. 05:26.090 --> 05:36.490 So if you try this like that and you try to copy the file again then it's not going to work and you 05:36.490 --> 05:37.000 get an error. 05:37.850 --> 05:38.890 Okay. 05:39.100 --> 05:44.930 So there are many other blanks you just need to google F S constants and you can look up a list. 05:44.960 --> 05:56.570 All right so now let's create a directory so the method to use is make directory. 05:56.910 --> 05:57.710 Okay. 05:57.910 --> 05:58.300 And we do. 05:58.390 --> 06:00.550 Doing this the async way. 06:00.550 --> 06:07.140 Otherwise you can use make directory sync or the synchronized way. 06:07.270 --> 06:10.790 You can also use copy file sync for the synchronous way. 06:11.140 --> 06:15.210 So we're gonna need the name of our directory service call it s CSM. 06:15.250 --> 06:18.420 For example. 06:19.040 --> 06:26.640 And then you pass a callback so let's copy our previous callback 06:33.400 --> 06:33.880 and 06:47.020 --> 06:48.570 now let's run our code 06:51.630 --> 06:57.450 and we can see that our folder has been created successfully. 06:57.450 --> 07:00.930 Now what if you want to use a path like 07:03.760 --> 07:04.240 this one 07:15.810 --> 07:17.180 for example. 07:17.340 --> 07:36.060 So let's try this and see what we get. 07:36.090 --> 07:39.350 Okay so this one doesn't work like this. 07:39.540 --> 07:51.160 So if you use a full path like this one you will need to add a parameter to the make directory method. 07:51.870 --> 08:01.110 So inside an object you can add options and the option you need here is recursive which you set to true. 08:01.410 --> 08:06.320 So now if you try this then it's going to create the parent folders as well. 08:06.360 --> 08:07.230 So it is Trina's 08:10.590 --> 08:17.080 mind if you go there you can see that we created both the parents folder and the folder itself. 08:17.830 --> 08:19.480 Okay. 08:20.170 --> 08:24.300 Now let's see how to remove a directory. 08:24.470 --> 08:35.080 So it's a very similar syntax but instead of make directory you use remove your x ray like that's okay 08:35.950 --> 08:39.040 so let's remove CSX 09:00.120 --> 09:02.910 you can see us our folder has been removed successfully. 09:04.620 --> 09:04.950 Okay.