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

Asked

Viewed 267 times

-1

I wanted to create a file in bath where the user chose the place where to perform the command DIR.

I’ve got it 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

This is my problem:

" Create from the command line a file with the name List2.bat, which allows you to store inside a file with the name Content2.txt, on the desktop, the contents of a directory provided by the user. "

  • Explain better how you want this choice to be made, and show what you’ve already got ready. Otherwise the question becomes too wide for the format of this site (take a look at [tour]).

  • Why delete the question, @Laérciolopes?

3 answers

0

@echo off && setlocal enabledelayedexpansion 

type nul >"%userprofile%\desktop\conteudo2.txt" & set /p "_pasta=digite uma pasta: "  

2<nul dir "!_pasta!" | find ".." >nul || goto :_nao

:_existe
rem :: copia p/ seu "Crtl+c" o conteudo do arquivo "%userprofile%\desktop\conteudo2.txt"
dir !_pasta!>>"%userprofile%\desktop\conteudo2.txt" && clip < "%userprofile%\desktop\conteudo2.txt"
echo file found & goto :_fim

:_nao
echo file not found

:_fim
echo/Pressione qualquer tecla para continuar. . . && timeout /t -1 >nul

0

I leave my script here ...

@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

0

Your code is correct, just skip the line before the command dir and of pause.

Thus remaining:

@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
  • It is not easier to use dir [caminho] direct? Why batch in this case?

  • Really? But she wants a batch...

  • The question is unclear. She may want this, she may want something much more complex like Midnight.

  • To me it seems very clear despite being very simple.

  • I don’t understand these requests to exclude the question.

  • By believing that this question will hardly help other users.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.