Experts Exchange connects you with the people and services you need so you can get back to work.
for %%a in ("%Folder%\%Mask%") do call :process "%%a"
for /f "usebackq delims=" %%a in ("%~1") do echo %~nx1 %%a&goto :eof)
Open in new window
Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.
' Define needed constants for I/O
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
' Define constants for files to process and lines to ouput
Const intLines = 2
Const blnHeader = True
' Create file system object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Get input folder name from command line
If (WScript.Arguments.Count > 0) Then
strBaseDir = WScript.Arguments(0)
WScript.Echo "No folder specified."
' Make sure it exists
If Not objFSO.FolderExists(strBaseDir) Then
WScript.Echo "Folder does not exist."
' Process each matching file
For Each objFile in objFSO.GetFolder(strBaseDir).Files
' Open input file
Set objRead = objFSO.OpenTextFile(objFile.Path, ForReading, False, TriStateUseDefault)
' Process first 'n' lines that we want, write to STDOUT
intCount = intLines
Do Until objRead.AtEndOfStream Or intCount = 0
intCount = intCount - 1
' Include file name if desired
If blnHeader Then
Wscript.Echo "[" & objFile.Name & "]" & objRead.ReadLine
' Close file
Set objRead = Nothing
for %%a in (*.txt) do (
set /p firstline=<%%a
nice idea, though I wonder if that reads the whole file or not?
have you tried yours...
12:00:01.09 - Start SET/p
The system cannot find the file specified.
12:00:01.13 - End SET/p
12:00:01.13 - Start VBScript
12:00:01.24 - End VBScript
12:00:01.26 - Start Process sub method...
The system cannot find the file Misc - Marketing.MBX.
12:00:02.68 - End Process sub method
pushd "C:\1. DATA\pmail\MAIL\eudora"
echo Scanning through 750Mb of Eudora conversion MBX text files
echo %time% - Start SET/p
(for %%a in (*.mbx) do (
set /p firstline=<"%%~a"
)) > ..\setp.txt
echo %time% - End SET/p
echo %time% - Start VBScript
cscript //nologo ..\firstline.vbs "C:\1. DATA\pmail\MAIL\eudora" > ..\vbscript.txt
echo %time% - End VBScript
echo %time% - Start Process sub method
(for %%a in (*.mbx) do call :process "%%a") >..\process.txt
echo %time% - End Process sub method
for /f "usebackq delims=" %%a in ("%~1") do echo "%~nx1" "%%~a"&exit /b)
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $37.50.
Premium members get this course for $62.50.
Premium members get this course for $174.99.
Premium members get this course for $151.20.
Premium members get this course for $108.00.
Premium members get this course for $79.20.
Premium members get this course for $167.20.