Batch Script: Parsing, File List

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
payyadi
Posts: 5
Joined: 18 Aug 2013 21:12

Batch Script: Parsing, File List

#1 Post by payyadi » 18 Aug 2013 21:25

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Script: Parsing, File List

#2 Post by foxidrive » 18 Aug 2013 23:38

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"

payyadi
Posts: 5
Joined: 18 Aug 2013 21:12

Re: Batch Script: Parsing, File List

#3 Post by payyadi » 19 Aug 2013 00:37

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch Script: Parsing, File List

#4 Post by foxidrive » 19 Aug 2013 06:00

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%"

Post Reply