file.txt" needs to remove directories from the results I use the following command to automatically unload compl...">

The command line "dir / b / s> file.txt" needs to remove directories from the results

I use the following command to automatically unload complete lists of files from a directory.

dir / b / sc: \ myfolder> c: \ mylist.txt

This works fine, but it displays the results with the full path, and also, beacuse I use a regex expression for the results that I need to display only the file names.

Any ideas?

+3
source share
6 answers

Change your regex to get the file name from all the way.

If you can use powershell, take a look Get-ChildItem. You may have more powerful options.

+2
source

, - , , , .

Windows (CMD.exe):

setlocal enabledelayedexpansion    
for /f "delims=" %a in ('dir /b /s c:\myfolder"') do (@echo %~nxa >>c:\mylist.txt)
endlocal

.BAT script :

setlocal enabledelayedexpansion    
for /f "delims=" %%a in ('dir /b /s c:\myfolder"') do (@echo %%~nxa >>c:\mylist.txt)
endlocal

, , , :

file1.fil
file2.fil
file3.fil

:

/f

  • dir /b /s, () ( ). , . file.txt C:\folder\file.txt.

"delims ="

  • for, % a %% a 1 .

% a (CMD.exe) %% a (.BAT)

  • , , . dir /b /s %% a .
  • : Loop 1: %% a = c:\folder\file1.fil Loop 2: %% a = c:\folder\file2.fil

dir/b/s

  • - (). /b /s, . dir () (), .

    • /b dir, .. .
    • /s dir ( ) .

do

  • - , , . , (@echo %%~nxa >>c:\mylist.txt)

@echo

  • - , , txt @echo %%~nxa >>c:\mylist.txt
  • >> c:\mylist.txt . , , txt . >, txt , . , script .

% ~ nxa (CMD.exe) %% ~ nxa (.BAT)

  • - %% a, , , () , @fightstarr20. C:\myfolder\myfile.fil myfile.fil
  • ~ %%~nxa , %% . n x.
  • n %%~nxa , %% a .

    • .

           -variable %%a = C:\folder\filename.fil 
           -variable %%~na = filename. 
      

      - , .fil .

  • x %%~nxa , %% a , , , .

    • .

           -variable %%a = C:\folder\filename.fil
           -variable %%~xa = .fil
      
  • , n x %% a , .

    • :

           -variable %%a = c:\folder\filename.fil
           -variable %%~nxa = filename.fil
      

setlocal enabledelayedexpansion

  • , script for, %% a "".

Endlocal

  • setlocal enabledelayedexpansion

CMD, ss64.com CMD. d dostips.com

+3

:

dir /b /s C:\myfolder>C:\temp.txt
echo exit>>C:\temp.txt
goto loop

:loop
set /p _x=<temp.txt
findstr /v /c:"%_x%" temp.txt>temp2.txt
type temp2.txt>temp.txt
set _x=%_x:*\=%
echo %_x%>file.txt
if "%_x%" == "exit" (
del temp.txt
del temp2.txt
exit
)
goto loop

goto, , . ...

+2

, , , , /s

dir /b c:\myfolder > c:\mylist.txt

That should do it.

0
source

This will certainly work as it works for me.

dir D: (file path) / s / b> d: \ filelist.txt

0
source

You can simply use this code:

dir /b > A_fileslist.txt

Copy inside the notepad editor and save as “Fileslist.bat”.

0
source

All Articles