Solved Dialog box Filter .txt

November 13, 2017 at 23:40:29
Specs: Windows 10

I have this code in my bat file.

set dialog="about:<input type=file id=FILE><script>;new ActiveXObject
set dialog=%dialog%('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);
set dialog=%dialog%close();resizeTo(0,0);</script>"

for /f "tokens=* delims=" %%p in ('mshta.exe %dialog%') do set "file=%%p"
echo selected file is : "%file%"

on this Window can use all files *.* . i need only .txt.

At the point where it is yellow I just want only ".txt"



See More: Dialog box Filter .txt

Report •

November 14, 2017 at 11:10:25
You can't with that technique. There are various VBScripts out there, but none of them seem to both work on my Win7 box, and give you the customization you're looking for. You could go PowerShell, but that'd limit you to Win7 and up.

How To Ask Questions The Smart Way

Report •

February 1, 2018 at 00:16:45
✔ Best Answer
You can do something like that :
@echo off
Title The absolute ultimate Browse for file dialog (w95 to w10) with start folder and filters
    echo Function GetFileDlgEx(sIniDir,sFilter,sTitle^) 
    echo Set oDlg = CreateObject("WScript.Shell"^).Exec("mshta.exe ""about:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);eval(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(0).Read("^&Len(sIniDir^)^+Len(sFilter^)^+Len(sTitle^)+41^&"));function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg(iniDir,null,filter,title)));close();}</script><hta:application showintaskbar=no />"""^) 
    echo oDlg.StdIn.Write "var iniDir='" ^& sIniDir ^& "';var filter='" ^& sFilter ^& "';var title='" ^& sTitle ^& "';" 
    echo GetFileDlgEx = oDlg.StdOut.ReadAll 
    echo End Function
    echo sIniDir = "C:\test.txt" 
    echo sFilter = "TXT files (*.txt)|*.txt|" 
    echo sTitle = "Please, select a text file" 
    echo MyFile = GetFileDlgEx(Replace(sIniDir,"\","\\"^),sFilter,sTitle^) 
    echo wscript.echo MyFile
for /f "tokens=* delims=" %%p in ('Cscript /NoLogo "%tmp%\%~n0.vbs"') do set "file=%%p"
echo %file%

This code is inspired from here How to add filter to a file chooser in batch?

message edited by Hackoo

Report •
Related Solutions

Ask Question