I don't know how to display selected files in notepad without extension

here is a first step, if you have an idea

@echo off
set dirpath=%1 
dir %dirpath% /b /o:gen > #Tree.txt
start notepad.exe #Tree.txt

Thanks for your quick reply "It Wasn't Me / Wasif Hasan"

In fact I select the files I want want to save the filename in a text file I use the send to command redirect to shortcut *.bat

I don't exactly know how to select files and execute your codes, it return me a blank file

For more precision I don't want a dialog box to open and look for a different filepath, it's to long I want in differents folders to select many files but not all, right click / send to / 'the batch program' and it will list me the files without extension in a text file open

Good solution I've adapt I need first a program to hide the console : command is 'cmdow @ /HID'

copy the file from ritchielawrence-cmdow-1bbcd2b\bin\Release\cmdow.exe to C:\Windows\System32


cmdow @ /HID
@echo off && SetLocal EnableDelayedExpansion & color 0a & mode 113,13

set "_file=C:\xxxmypathxxx\#Tree.txt" && if /i not exist "%APPDATA%\Microsoft\Windows\SendTo\%~nx0"  (
copy "%~dpnx0" "%APPDATA%\Microsoft\Windows\SendTo\" ) else (
<nul cd.>"!_file!" && for %%# in (%*)do echo/%%~n#>>"!_file!")
type "!_file!" | clip & "%__APPDIR__%notepad.exe" "!_file!" 
  • Use forfiles instead of dir. – Akina Dec 23 '19 at 13:56
  • Changing your question after you've received answers is inappropriate, as it invalidates the answers you've received. It can even make those answers wrong, and adversely affect the reputation of those who answered. If you now have a new or additional question, create a new post and ask it there; you can link back to this one if needed for reference. – DavidPostill Jan 15 at 19:18
  • Sorry, I'm new on the forum – Bob Jan 16 at 10:31

  • Maybe some like this?
@echo off && SetLocal EnableDelayedExpansion & color 0a & mode 113,13

set "_file=%~dp1!random!.txt" && if /i not exist "%APPDATA%\Microsoft\Windows\SendTo\%~nx0"  (
copy "%~dpnx0" "%APPDATA%\Microsoft\Windows\SendTo\" ) else (
<nul cd.>"!_file!" && for %%# in (%*)do echo/%%~n#>>"!_file!")
type "!_file!" | clip & "%__APPDIR__%notepad.exe" "!_file!"

  • Update:
    • 1) Just copy code and save like: list_name.cmd
    • 2) Click in list_name.cmd and select your files
    • 3) List.txt will by created in same folder where the list_name.cmd are
    • 4) The List.txt will open by list_name.cmd whend finished this job

Obs.: This is a simply adapted code/cmd to run in hybrid cmd/vbs/ps1 script, and, this also, is from another adapted script by goncons and they sources are here!

enter image description here

<!-- ::
@echo off && cls && mode con:cols=60lines=5 & title Select Files^!
<nul cd.>.\List.txt
for /f tokens^=* %%i in ('%__APPDIR__%CScript //NoLogo "%~f0?.wsf"
   ')do if not "%%~i" == "NO Files Selected" ( set "_n=%%~ni" && (
     cmd /v /c echo/!_n!>>.\List.txt)) else echo/Canceled  By User^!
if exist .\List.txt type .\List.txt |findstr . >nul && start "" /b .\List.txt
exit /b
# -->

<job><script language="vbscript">
Private Function SelectFiles(InitialDir, Filter)
    Dim result : result = ""
    With WScript.CreateObject("WScript.Shell").Exec( _
        "powershell.exe -NonInteractive -NoProfile -NoLogo -Command ""& {" & _
            "[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms');" & _
            "$objOFDialog = New-Object System.Windows.Forms.OpenFileDialog;" & _
            "$objOFDialog.Filter = '" & Filter & "';" & _
            "$objOFDialog.InitialDirectory = '"  & InitialDir & "';" & _
            "$objOFDialog.Multiselect = $True;" & _
            "$objOFDialog.RestoreDirectory = $True;" & _
            "$objOFDialog.ShowHelp = $True;" & _
            "$objOFDialog.SupportMultiDottedExtensions = $True;" & _
            "$objOFDialog.Title = 'SelectFiles (" & InitialDir & ")';" & _
            "[void]$objOFDialog.ShowDialog();" & _
            "$objOFDialog.FileNames -join '|'" & _
        .StdIn.Close ' Important if not the script hangs:

        While .Status = 0
            WScript.Sleep 100
        Wend ' .Status = 0
        if .ExitCode = 0 Then
            While Not .stdOut.AtEndOfStream
                result = result & .stdOut.ReadAll
            Wend ' Not .stdOut.AtEndOfStream
            ' Convert the string to an array of file paths
            SelectFiles = Split(Replace(result, vbCrLf, ""), "|")
            While Not .stdErr.AtEndOfStream
                result = result & .stdErr.ReadAll
            Wend ' Not .stdErr.AtEndOfStream
            WScript.Echo result
            SelectFiles = False
        End If ' .ExitCode = 0
    End With ' WScript.CreateObject("WScript.Shell").Exec(...)
End Function ' SelectFiles

Dim SelectedFiles
SelectedFiles = SelectFiles(".", "Text Files *.*")

If IsArray(SelectedFiles) Then
    If UBound(SelectedFiles) >= 0 Then
        WScript.Echo "Selected Files: " & Join(SelectedFiles, vbCrLf)
        WScript.Echo "NO Files Selected"
    End If ' UBound(SelectedFiles) >= 0

    WScript.Quit 0
    WScript.Quit 1
End If ' IsArray(SelectedFiles)

By editing the 5th line in set "_n=%%~ni, you also can get:

set "_n=%%~xi"         x = will save .ext only
set "_n=%%~ni"         n = will save name only
set "_n=%%~pi"         p = will save path only
set "_n=%%~di"         d = will save drive only
set "_n=%%~fi"         f = will save full path
set "_n=%%~dpnxi"   dpnx = will save full path

type 'for /?' there is more optins in help command... 

  • Old Post

This presumes that are you using this command layout:

file.bat c:\some\path\for\argument

In your code, the %~1 == 1st argument

You can do this using a for loop with expanded variable inner

You don’t need to set a variable %dirpath% for using %1.

Because this you can use directly use: dir %1, like:

  • For only names without extension:
@echo off 

>nul cd.>.\#Tree.txt && for /f ^tokens^=* %%i in ('
dir "%~1\*.*" /b /o:gen')do echo=%%~ni>>.\#Tree.txt

if exist .\#Tree.txt @start notepad.exe .\#Tree.txt

  • For full path names without extension:
@echo off 

>nul cd.>.\#Tree.txt && for /f ^tokens^=* %%i in ('
dir/b/o:gen "%~1\*.*"')do echo=%%~dpni>>.\#Tree.txt

if exist .\#Tree.txt @start notepad.exe .\#Tree.txt

For loop explained here

| improve this answer | |

You can use forfiles:

  • Only file names
@echo off
if exist "%~1" forfiles /p "%~1" /m *.* /c "cmd /c echo @file" >#tree.txt
if exist ".\#tree.txt" notepad.exe .\#tree.txt
  • File names + extensions
@echo off
if exist "%~1" forfiles /p "%~1" /m *.* /c "cmd /c echo @file.@ext" >#tree.txt
if exist ".\#tree.txt" notepad.exe .\#tree.txt
| improve this answer | |
  • The first code snippet seems to still include file extensions. – Anaksunaman Dec 27 '19 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.