Zinger
Zinger

Reputation: 443

Batch: Open first folder in directory

Is there a way to open the first folder in a directory without knowing it's name?

If Command Prompt says

C://Users/Me/Desktop/Folder1

Imagine Folder2 is inside Folder1. I could easily just type:

cd Folder2

But Is there a way to do it if I didn't know it was called Folder2?

For example:

cd[0]

Do the folders have an index?

Help would be appreciated.

Tell me if I need to clarify the question.

Upvotes: 3

Views: 2325

Answers (1)

soja
soja

Reputation: 1607

This batch file will do change to the first directory in the current directory (or none, if there aren't any).

@echo off
for /d %%a in (*) do cd "%%~a"&&exit /b

There is no such thing as a folder index in Batch.

Upvotes: 4

Related Questions