Solved Move the files based on a string value

January 30, 2017 at 08:20:01
Specs: Windows 7
HI ,

I am trying to write a batch script for the below scenario, but I am not able to get the code working properly as I expected.

Its 50% working not sure where I am doing it wrong.

What I am trying to do is :-

I have a list of files (pipe delimiter) in \\netrtn\ (filename starting with CDR*) , the file data will have a string 'Source' or 'Target' of a Record which starts with 1BA, I am trying to search the string 'Source' and 'Target' and move the files to corresponding folders ( i.e. if the file contains 'source' string I am moving the file to \\netrtn\Source and if the file contains the 'target' string I am moving the file to \\netrtn\Target) and if the files doesn't contain any source or target strings I am generating a .txt with a list of all the files which don't have a string.


What I have done till now, I am using the below script, the script is searching fir the 'Source' string and moving the files correctly but the second part of searching for 'Target' string ands move to target folder is not working.

@echo OFF
setlocal enableextensions disabledelayedexpansion

set "source=\\netrtn\CDR*"
set "target=\\netrtn\Source"
set "target1=\\netrtn\Target"
set "searchString_SRC=Source"
set "searchString_TGT=Target"

set "found="
for /f "delims=" %%a in ('
findstr /m /i /l /c:"%searchString_SRC%" "%source%" 2^>nul
') do (
if not defined found set "found=1"
move "%%a" "%target%"
)

set "found="
for /f "delims=" %%a in ('
findstr /m /i /l /c:"%searchString_TGT%" "%source%" 2^>nul
') do (
if not defined found set "found=1"
move "%%a" "%target1%"
)

if not defined found (
Failure
)


See More: Move the files based on a string value

Report •

#1
January 31, 2017 at 01:46:52
✔ Best Answer
Post a few lines of a few files

=====================

M2 Get custom script or take private lessons


Report •

#2
January 31, 2017 at 13:06:01
I figured it out..Thanks anyways

message edited by sandhya_98


Report •
Related Solutions


Ask Question