Tuesday, April 30, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 5470  / 3 Years ago, wed, july 21, 2021, 11:10:56

This is what I am trying to achieve.




  • I have two folders SRC and DESTINATION. SRC contains several subdirectories and files in it.

  • A batch file should be built upon clicking it the following should be done

    1. Delete all contents from DESTINATION folder

    2. Copies all the files/subdirectories from SRC to DESTINATION




Can someone help me with this ?.



If this activity requires significant effort (I don’t know whether the above is simple to implement or not), do point me some resources for me to dig into it.


More From » command-line

 Answers
5

Create the following file using your favorite (plain) text editor (e.g. gedit or kwrite)



#!/bin/bash

source_dir=SRC
dest_dir=DESTINATION

rm -rf "$dest_dir/*" #Remove the contents of DESTINATION
cp -r "$source_dir/* $dest_dir/" #Copy the contents of SRC into DESTINATION


The above should be saved with a meaningful name; e.g. copy_SRC_to_DESTINATION.sh and made executable with



chmod +x /path/to/copy_SRC_to_DESTINATION.sh


from a terminal



Now, in your file manager, navigate to where you saved the file, double-click on it and choose "Run".



Notes




  • As onse commented, you should edit the script file and manually enter the actual names of your directories instead of SRC and DESTINATION in the above listing.

  • Replace /path/to/ in the chmod line above with the actual path where you saved the script file.


[#29528] Wednesday, July 21, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eryeath

Total Points: 122
Total Questions: 121
Total Answers: 112

Location: Saint Helena
Member since Fri, Aug 26, 2022
2 Years ago
;