Hi Frnds,
As I'm very new to Batch scripting, I need your help in accomplishing below job,
* I need a script for which I will pass 3 Arguments.
1. Source files path.
2. FIleList.txt name.
3. Source feed name.
* Now in script taking the 3rd Argument(source feed name) we should parse through all the filenames in the Source files path(1) and pick all the names with Source feed name specified and put all those names to FileList.txt.
Example:
* 1. "D:/SrcFiles"
2. D:/project/filenames.txt
3. SRC
@ D:/srcfiles I have files like SRC_1.txt, SRC_table.doc, TGT_1.txt, TGT_Table.doc
Output in my filenames.txt should be
D:/srcfiles/SRC_1.txt
D:/srcfiles/SRC_table.doc
Batch Script: Parsing, File List
Moderator: DosItHelp
Re: Batch Script: Parsing, File List
This is untested -see if it does what you need.
Code: Select all
@echo off
set "source=%~1"
set "file=%~2"
set "search=%~3"
dir "%source%" /b /a-d | find "%search%" >"%temp%\searchfile.tmp"
for /f "delims=" %%a in (' type "%temp%\searchfile.tmp" ') do >>"%file%" echo "%source%\%%a"
del "%temp%\searchfile.tmp"
Re: Batch Script: Parsing, File List
Thanks a ton foxidrive.
Below is the script I wrote to accomplish it.
@echo off
setlocal enabledelayedexpansion
set "parentfolder=%CD%"
set srcpath=%1%
set mylist=%2%
set srcfeed=%3%
for /r %srcpath% %%g in (*%srcfeed%*.*) do (
set "var=%%g"
set var=!var:%parentfolder%=!
echo !var! >> %mylist%
)
(Let me please know if this is fine of has some performance hindrance)
Now With this I want to keep one more question,
The file list I have got has data like,
D:\FOLDER\SRC_1.txt
D:\FOLDER\SRC_PS.txt
Having this data I want only these files listed in the .txt file to be archived to different folder.
How this can be achieved?
Below is the script I wrote to accomplish it.
@echo off
setlocal enabledelayedexpansion
set "parentfolder=%CD%"
set srcpath=%1%
set mylist=%2%
set srcfeed=%3%
for /r %srcpath% %%g in (*%srcfeed%*.*) do (
set "var=%%g"
set var=!var:%parentfolder%=!
echo !var! >> %mylist%
)
(Let me please know if this is fine of has some performance hindrance)
Now With this I want to keep one more question,
The file list I have got has data like,
D:\FOLDER\SRC_1.txt
D:\FOLDER\SRC_PS.txt
Having this data I want only these files listed in the .txt file to be archived to different folder.
How this can be achieved?
Re: Batch Script: Parsing, File List
If you are searching recursively then this will work too:
Code: Select all
@echo off
set "source=%~1"
set "file=%~2"
set "search=%~3"
dir "%source%" /b /s /a-d | find "%search%" >"%file%"