<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Preetpal Basson</title>
    <description>The latest articles on DEV Community by Preetpal Basson (@pbasson).</description>
    <link>https://dev.to/pbasson</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2234493%2Ff772f3f7-e106-4c1e-9346-e97410551e06.jpeg</url>
      <title>DEV Community: Preetpal Basson</title>
      <link>https://dev.to/pbasson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pbasson"/>
    <language>en</language>
    <item>
      <title>Directories created using Alphabets (A to Z) from Current Directory</title>
      <dc:creator>Preetpal Basson</dc:creator>
      <pubDate>Sat, 19 Oct 2024 23:07:58 +0000</pubDate>
      <link>https://dev.to/pbasson/directories-created-using-alphabets-a-to-z-from-current-directory-19ik</link>
      <guid>https://dev.to/pbasson/directories-created-using-alphabets-a-to-z-from-current-directory-19ik</guid>
      <description>&lt;p&gt;Have you ever wanted to organise your files and directories systemically. &lt;br&gt;
Well a script has been designed with that very purpose in mind. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Alphabet-MkDirs.sh&lt;/code&gt; is a script designed to make Directories from A to Z using current Directory. Will make either Normal or Static directories based on user Selection.&lt;/p&gt;

&lt;p&gt;When the script has been executed the following options appear: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Normal: Creates the A to Z directories based on current directory name&lt;/li&gt;
&lt;li&gt;Static: Creates the A to Z directories based on current directory name and create an empty file that means directory must be manually deleted 

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;find . -type d -empty -delete&lt;/code&gt; would remove all empty directory as in Normal selected. Static would prevent this, hence manual removal.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;_ToSort: This creates additional directory 

&lt;ul&gt;
&lt;li&gt;eg &lt;code&gt;TestingDirectory/TestingDirectory-T/ToSort-TestingDirectory/ToSort-TestingDirectory-001&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Navigate to directory that you wish to create directories in. 

&lt;ol&gt;
&lt;li&gt;eg &lt;code&gt;$USER/Downloads/TestDirectory&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Execute the BASH script from the command line

&lt;ol&gt;
&lt;li&gt;eg &lt;code&gt;bash $HOME/bashscripts/bashscripts-M/MkDirs-Script/Alphabet-MkDirs/Alphabet-MkDirs.sh&lt;/code&gt;

&lt;ol&gt;
&lt;li&gt;Change the above path to where you have the script. This must be an Absolute path otherwise you cannot run this from any directory as expected. &lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Select one of the Script options

&lt;ol&gt;
&lt;li&gt;Normal: &lt;/li&gt;
&lt;li&gt;Normal_ToSort:
&lt;/li&gt;
&lt;li&gt;Static:&lt;/li&gt;
&lt;li&gt;Static_ToSort:
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Directories outputted to terminal

&lt;ol&gt;
&lt;li&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdgjgvkr67i4oh64m2ode.png" alt="Directory Output" width="800" height="476"&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Sorting commence 

&lt;ol&gt;
&lt;li&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfzwn90qd324zgsz56g9.png" alt="Directories" width="800" height="91"&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let me know if this was useful or have any questions. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/pbasson/bashscripts_github/blob/master/bashscripts_github-M/MkDirs-Script/Alphabet-MkDirs/Alphabet-MkDirs.sh" rel="noopener noreferrer"&gt;GitHub Script&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash

# Change Path below to reflect when script is being executed on local. eg `bash $HOME/Downloads/Alphabet-MkDirs.sh`
# bash $HOME/bashscripts/bashscripts-M/MkDirs-Script/Alphabet-MkDirs/Alphabet-MkDirs.sh

# AUTHOR: PREETPAL BASSON
# PURPOSE: Make Directory from A to Z using current Directory. Will make either Normal or Static directories. Static means directory will not be deleted as empty, 
# PREREQUISITE: Execute from Current Directory to creates new Directories 

function header(){
    echo "-----------------------------"
    echo "# Script - $1"
    echo
}


function staticselect() {
    echo "Please Select An Directory Builder?"
    select list in Normal Normal_ToSort Static Static_ToSort Exit
    do
        case $list in
                Normal)
                    IS_STATIC=false
                    IS_SORT=false
                    echo &amp;amp;&amp;amp; echo " $list Has Been Selected "
                    break
                ;;
                Normal_ToSort)
                    IS_STATIC=false
                    IS_SORT=true
                    echo &amp;amp;&amp;amp; echo " $list Has Been Selected "
                    break
                ;;
                Static)
                    IS_STATIC=true
                    IS_SORT=false
                    echo &amp;amp;&amp;amp; echo " $list Has Been Selected "
                    break
                ;;
                Static_ToSort)
                    IS_STATIC=true
                    IS_SORT=true
                    echo &amp;amp;&amp;amp; echo " $list Has Been Selected "
                    break
                ;;
                Exit)
                    echo &amp;amp;&amp;amp; echo "Script will now exit"
                    exit
                    break
                ;;
                *)
                    echo "Invalid Option"
                ;;
        esac
    done
}

function initialize() {
    FULL_PATH="$PWD"
    CUR_DIR=${PWD##*/}
    IS_STATIC=false
    IS_SORT=false
    T_CHAR="T"
}

header "START"

initialize

staticselect

for n in {A..Z}
do
    CUR_PATH=$(printf "$FULL_PATH/$CUR_DIR-$n")

    if [ ! -d $CUR_PATH ]; then
        mkdir -vp "$CUR_PATH"
    fi
    if [[ -d $CUR_PATH &amp;amp;&amp;amp; "$IS_STATIC" = true ]]; then
        touch "$CUR_PATH/.$CUR_DIR-$n"
        echo "$(printf "$CUR_DIR-$n")/.$CUR_DIR-$n" &amp;gt;&amp;gt; "$CUR_PATH/.$CUR_DIR-$n"
    fi
    if [[ "$n" == "$T_CHAR" &amp;amp;&amp;amp; "$IS_SORT" == "true" ]]; then
        mkdir -vp "$CUR_PATH/ToSort-$CUR_DIR/ToSort-$CUR_DIR-001"
    fi
done 

header "END"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cli</category>
      <category>shell</category>
      <category>tutorial</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
