Keith Aquino
Keith Aquino

Reputation: 17

How to list down hidden files using a .BAT File?

For my computer project, my teacher requires us to make a bat file that lists down hidden files. The whole class doesn't know how though. Here is my code so far:

@echo off
set /p UserInput=What directory would you like?
cd %UserInput%
dir /S /aH
Pause

My teacher says I'm almost done, I'm just missing 2 or 3 characters after "dir /S /aH". Would anyone know what these missing characters are?

Hi guys, I'm sorry for the late reply. We're having so many projects before the semester ends. :( When I run the bat file, it shows the following.. Here's the link: imgur.com/W4Wm4vP

Upvotes: 1

Views: 1986

Answers (1)

Compo
Compo

Reputation: 38604

Whilst you've already received responses that are sufficient to your initial request, I've added one just to show that you should really try to perform some sort of verification of user input before proceeding with your listing:

@ECHO OFF
:LOOP
CLS
SET /P "UserInput=What directory would you like? "
IF "%UserInput%"=="" GOTO LOOP
IF /I NOT "%CD%"=="%UserInput%" (PUSHD "%UserInput%" 2>NUL||GOTO LOOP)
DIR /B /S /AH-D
TIMEOUT /T -1 /NOBREAK

I trust this will give you a few more things to research and learn.

Edit
As an after thought, if the end user is inputting only a directory name and not a full path then you may need to replace line six with:

FOR %%A IN ("%CD%") DO IF /I NOT "%%~nxA"=="%UserInput%" (
    PUSHD "%UserInput%" 2>NUL||GOTO LOOP)

Upvotes: 2

Related Questions