Create a bath file that performs the DIR of a folder or sets of folders that the user chooses

-2

I wanted to create a file in bath where the user would choose the location where to execute the command DIR .

I have this done:

@echo off

set /p pasta=digite uma pasta: dir %pasta%>>c:\conteudo2.txt

if exist %pasta% goto existe

if not exist %pasta% goto nao

:existe

echo file found

goto fim

:nao

echo file not found

:fim pause

My problem is this:

  

"Create from the command line a file named Listar2.bat, which allows the contents of a user-supplied directory to be stored inside a file named Content2.txt on the desktop."

    
asked by anonymous 22.05.2018 / 20:14

2 answers

0

I leave here my script ...

@echo off
mode 70,8
:main

echo.&echo. Arraste uma pasta e dˆ enter.
set /p caminho=^>:

if not defined caminho (cls &goto main)
set caminho=%caminho:"=%
if not exist "%tmp%\Lista-dir" (md "%tmp%\Lista-dir")

cls
echo.&echo. Escolha uma Op‡Æo: &echo.

echo. [1] - Listar somente pastas
echo. [2] - Listar somente pastas e Subpastas
echo. [3] - Listar pastas, Subpastas e arquivos.

CHOICE /c "123" /n /M:

if %errorlevel% equ 1 (dir /b "%caminho%">%tmp%\Lista-dir\listagem.txt)
if %errorlevel% equ 2 (tree /a "%caminho%">%tmp%\Lista-dir\listagem.txt)
if %errorlevel% equ 3 (tree /a /f "%caminho%">%tmp%\Lista-dir\listagem.txt)

explorer %tmp%\Lista-dir\listagem.txt
    
23.05.2018 / 02:56
0

Your code is correct, you just need to skip the line before the command dir and pause .

Looking like this:

@echo off

set /p pasta=digite uma pasta:

dir %pasta%>>c:\conteudo2.txt

if exist %pasta% goto existe

if not exist %pasta% goto nao

:existe

echo file found

goto fim

:nao

echo file not found

:fim

pause
    
22.05.2018 / 20:30