Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:37:28+00:00 2026-06-13T02:37:28+00:00

Say I have this folder structure: MainFolder Folder1 Folder2 Folder3 … Folder200 I want

  • 0

Say I have this folder structure:

MainFolder
    Folder1
    Folder2
    Folder3
    ...
    Folder200

I want to write a script that, if I am current inside Folder2 and execute the script, it will automatically change to the next directory in the list, in this case, Folder3. The restrictions are that the folders could have any name, and I cannot rename it.

So my questions are:

1) How can I know what directory is next on the list? I was wondering if the subdirectories of a directory have a sequential index number that I could use to know what dir comes next.

2) Since I would like to display the name of the new directory at the end of the script, is there a way to display only the dir name? (eg: Folder3 instead of /home/path/to/dir/Folder3 which is the result of “pwd”)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:37:30+00:00Added an answer on June 13, 2026 at 2:37 am
    1. What defines the order in which the directories are to be processed? If you have directories without spaces and other special characters in their names, you can use ls to list the directories in order, and then find the name after the current directory:

      cwd=$(basename $PWD)
      nwd=$(ls .. | awk "/^$cwd$/ { found = 1; next; } { if (found) { print; found = 0 } }")
      if [ -d ../$nwd ]
      then cd ../$nwd
      fi
      
    2. The name of the directory (only) is found using basename $PWD or ${PWD##*/}.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a structure like this: <folder name=folder1> <folder name=folder2> <bookmark href=link.html>
Say I have this file structure Soultion-> Folder1 -> FileIwant.html So this could be
I'm wondering if anyone can do this. Say I have this folder structure: Folder
Let's say that I have this website file root structure: frontend /home/username/public_html/ backend /home/username/public_html/admin/
Say I have this url: http://site.example/dir/ In this folder I have these files: test.ascx.cs
Say i have this this structure. MyApp ├── main.py └── package ├── __init__.py ├──
Lets say we have the following file and [folder] structure in a project with
I have a folder structure like this: package_name/ |-- module1 |-- module2 |-- module3
My first post - firstly have to say that this site is great -
Let's say I have the following filesystem structure: /app/ Main application folder /app.js Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.