Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: sorting the files into 2 different folders base on a phrase in the file  (Read 3014 times)

0 Members and 1 Guest are viewing this topic.

QK

    Topic Starter


    Rookie
    I need to create an execute program to sort the files into 2 different folders base on a word or a phrase. Let say I have 4 files, DSNO001, DSNO002, DSNO003, DSNO004 in Folder A. Only DSNO002 contains "Company ABC" which I want to put in Folder B, the other 3 files move to Folder C.  How can I do it? Any expert can help me? 

    burton



      Beginner
    • I love YaBB 1G - SP1!
      Re: sorting the files into 2 different folders base on a phrase in the file
      « Reply #1 on: October 30, 2007, 06:16:43 AM »
      Have you already read this section?
      http://www.computerhope.com/batch.htm

      James2000

      • Guest
      Re: sorting the files into 2 different folders base on a phrase in the file
      « Reply #2 on: October 30, 2007, 12:01:37 PM »
      Hi QK,

      Assuming you are using Windows XP, the following MS-DOS batch-file should do the job...
      Code: [Select]
      @echo off
      if not exist Folder_A  md Folder_A
      if not exist Folder_B  md Folder_B

      for %%A in (*.txt) do (
        find "Company ABC" %%A>nul
        if errorlevel 1 (move %%A Folder_A) else (move %%A Folder_B)
      )


      Here is an example of running this batch-file...
      Code: [Select]
      D:\TEST> dir /b
      DSNO001.txt
      DSNO002.txt
      DSNO003.txt
      DSNO004.txt
      FileSorter.bat

      D:\TEST> FileSorter

      D:\TEST> dir /b
      Folder_A
      Folder_B
      FileSorter.bat

      D:\TEST> dir /b Folder_A
      DSNO001.txt
      DSNO003.txt
      DSNO004.txt

      D:\TEST> dir /b Folder_B
      DSNO002.txt

      D:\TEST>

      Hope that helps,
      James