Search Contents and Move
Moderators: Dorian (MJT support), JRL
Search Contents and Move
Hi there,
I would like to do this if possible.
Search a folder containing thousands of .eml files.
If they have the text "RRR_" within their contents, I want to have them moved to a different folder.
e.g. Search C:\Temp
If any *.eml files contain the text "RRR_"
Move the files to C:\sorted.
There could be several thousand files.
File example: C:\TEMP\asdfgr123a2grl.eml (the file names are random characters)
Criteria: any .EML file containing "RRR_"
I would like to do this if possible.
Search a folder containing thousands of .eml files.
If they have the text "RRR_" within their contents, I want to have them moved to a different folder.
e.g. Search C:\Temp
If any *.eml files contain the text "RRR_"
Move the files to C:\sorted.
There could be several thousand files.
File example: C:\TEMP\asdfgr123a2grl.eml (the file names are random characters)
Criteria: any .EML file containing "RRR_"
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Quick thought:
Use the Dos FIND command and use RunProgram to call the batch file, and use Macro Scheduler commands to parse the results and move the files between directories.
RunProgram> cmd /c find /C "RRR_" c:\temp\*.eml > filelist.txt
This will result with a list of files (filelist.txt) that have "RRR_". They will have a number >0 after the colon. The number represents the number of lines that contain the string. Here is a sample extract
Now parse the filelist.txt for those lines with number >0
Use Position> and MidString> to extract the file names and write to a variable that will be a list of the files to Move.
Now just use normal Move command
Use the Dos FIND command and use RunProgram to call the batch file, and use Macro Scheduler commands to parse the results and move the files between directories.
RunProgram> cmd /c find /C "RRR_" c:\temp\*.eml > filelist.txt
This will result with a list of files (filelist.txt) that have "RRR_". They will have a number >0 after the colon. The number represents the number of lines that contain the string. Here is a sample extract
Code: Select all
---------- FIREFOX.EXE_TRACE.TXT: 0
---------- GETENVVALUE.TXT: 0
---------- TEMP.TXT: 1
---------- TEST.TXT: 1
Use Position> and MidString> to extract the file names and write to a variable that will be a list of the files to Move.
Now just use normal Move command
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Here's another way. A quick and dirty sample script. Bob's DOS method will work as well. I have no idea which way will be faster. With 1000s of files speed may be a concern.
Code: Select all
//Set thesethree lines as needed
Let>FileLoc=C:\temp\*.eml
Let>FileDest=C:\sort\
Let>TextToFind=RRR_
GetFileList>%FileLoc%,list
Separate>list,;,item
Let>kk=0
Repeat>kk
Add>kk,1
Let>pathfilename=item_%kk%
Separate>pathfilename,\,fname
Let>filename=fname_%fname_count%
Readfile>pathfilename,result
Separate>result,TextToFind,test
If>%test_count%>1
Let>CF_OVERWRITE=1
CopyFile>pathfilename,%FileDest%%filename%
Message>copying %pathfilename% to%CRLF%%FileDest%\%filename%
EndIf
Until>kk,%item_count%
Last edited by JRL on Thu Jan 29, 2009 11:03 pm, edited 1 time in total.
Thanks JRL
I have tried below = but the files are not being copied across to the dest folder? can you please help me?
by the way your a legend!
[/code]
by the way your a legend!
[/code]
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Enhancing Bob's suggestion, this DOS command line only prints to the file the names of the files containing the string (so you don't need the second search step).
Note that there are no spaces before or after the ">".
Code: Select all
RunProgram>cmd /c findstr /i /s /m "rhubarb" c:\temp\*.txt>c:\temp\tart.txt
-
- Automation Wizard
- Posts: 1101
- Joined: Fri Jan 07, 2005 5:55 pm
- Location: Somewhere else on the planet
Here's another idea, this one scans the files one by one and if it finds the target text writes the name of the file to a txt file. This would be a good way to test if it is going to work before you run a version that actually moves the files, you can check the text file and it will show you the list of files that would be moved. I suggest you try it with a subset of files eg a*.eml because scanning 40,000 files is going to take a very long time.
Code: Select all
Let>RP_WAIT=1
DeleteFile>c:\temp\flist.txt
GetFileList>c:\temp\*.txt,files
Separate>files,;,file_names
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
DeleteFile>c:\temp\tart.txt
let>myfile=file_names_%k%
RunProgram>cmd /c findstr /i /s /m "rhubarb" %myfile%>c:\temp\tart.txt
FileSize>c:\temp\tart.txt,size
If>size=0,jump
Readln>c:\temp\tart.txt,1,datafile
WriteLn>c:\temp\flist.txt,res,datafile
Label>jump
Until>k,file_names_count
Label>end
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
Hey ME_again. Thanks for the reminder about findstr. I am still thinking DOS 3.0, and forgot about the newer command.
Remember edlin?
Both FIND and FINDSTR will result in a list of the files almost immediately, but the FINDSTR will be better, needs no parsing to reduce the list, I like it!
And that was a nice touch associating rhubarb with tart.
Remember edlin?
Both FIND and FINDSTR will result in a list of the files almost immediately, but the FINDSTR will be better, needs no parsing to reduce the list, I like it!
And that was a nice touch associating rhubarb with tart.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
Rhubarb and Tart
Hi Me_Again,
Its me again hehe
I have tried the code you supplied. Thanks Heaps. I am trying to avoid the memory error I am receiving with the other option.
My .eml files are located C:\Inetpub\mailroot\mail\
An example of a file name is ddf23122ee33404f.eml (totally random)
an example of the contents of one of these .eml files is as follows:
As you can see it is the "PCC_" that I am wanting to filter by.
I run the above, and the only thing that happens is the command prompt (cmd.exe) is executed by macro scheduler and it just sits there doing not much else!
Any ideas?
(i wish I could come up with code as quick as you guys!)
cheers
AM from New Zealand
[/code]
Its me again hehe
I have tried the code you supplied. Thanks Heaps. I am trying to avoid the memory error I am receiving with the other option.
My .eml files are located C:\Inetpub\mailroot\mail\
An example of a file name is ddf23122ee33404f.eml (totally random)
an example of the contents of one of these .eml files is as follows:
Code: Select all
%A2%B <b>
%C290120090833%D00%E08%G015526%O010270%Q000000%P0158%R000000%S0000%T000000%U0000%V010270%W00052920%X00037130%Y0%z5D8C
Code: Select all
Let>RP_WAIT=1
DeleteFile>C:\Inetpub\mailroot\mail\test\flist.txt
GetFileList>C:\Inetpub\mailroot\mail\*.eml,files
Separate>files,;,file_names
If>file_names_count=0,end
Let>k=0
Repeat>k
Let>k=k+1
DeleteFile>C:\Inetpub\mailroot\mail\test\tart.txt
let>myfile=file_names_%k%
RunProgram>cmd /c findstr /i /s /m "PCC_" %myfile%>C:\Inetpub\mailroot\mail\test\tart.txt
FileSize>C:\Inetpub\mailroot\mail\test\tart.txt,size
If>size=0,jump
Readln>C:\Inetpub\mailroot\mail\test\tart.txt,1,datafile
WriteLn>C:\Inetpub\mailroot\mail\test\flist.txt,res,datafile
Label>jump
Until>k,file_names_count
Label>end
Any ideas?
(i wish I could come up with code as quick as you guys!)
cheers
AM from New Zealand
[/code]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
1. On the forum Disable HTML Code and see if that fixes the coding errors on the posting.
2. If you did cut/paste from forum be sure to remove trailing spaces that are not wanted.
3. Have you tried to single step through the code?
Using the WatchList, are the variables what you expect them to be?
4. What OS do you have? If using WIN9x, you may need to replace cmd with command.com
2. If you did cut/paste from forum be sure to remove trailing spaces that are not wanted.
3. Have you tried to single step through the code?
Using the WatchList, are the variables what you expect them to be?
4. What OS do you have? If using WIN9x, you may need to replace cmd with command.com
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!