1.

Solve : copy files to different direcotry when they match specific string.?

Answer»
I have a file that contains list of SEARCH strings (like ABCDE, XYZ etc..) separated by new line.

I have a source folder where there are around 35000 files (.txt).

We need the destination folder populated (copied ) with matching files...

I have to do this in MS DOS. can anybody give me a batch file...or vbscript.....

thanks,
rav.Your question is a bit ambiguous. Do the files get copied to different destinations depending on which string they match? What if a file name matches none of the string arguments?

How many string arguments are there? Might be easier to hardcode an array rather than load array from file.

Your profile mentions your OS as Linux Variant. VBscripts run in Windows or the SHELL program. They do not run in MS-DOS.

Code: [Select]Const ForReading = 1

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("search.txt", ForReading)

'Load Array
i - 0
Do Until f.AtEndOfStream = True
ReDim Preserve arrSearch(i)
arrSearch(i) = f.ReadLine
i = i + 1
Loop
f.Close
'End Load Array

Set f = fso.GetFolder("c:\source")
Set fc = f.Files

For Each fs In fc
For Each arg In arrSearch
If INSTR(1, fs.Name, arg) > 0 Then
fso.CopyFile fs.PATH, "c:\dest", True
End If
Next
Next

Save file with a vbs EXTENSION and run from the command prompt as cscript scriptname.vbs

You will need to add path information to match your environment.

Good luck. linux variant? BASH?


you can use the question mark ? to fill in unkowns

for example, instead of dir file393039*.txt , dir file???*.txt


Discussion

No Comment Found