1.

Solve : Sorting files to different folders - Help~?

Answer»

I need to create a batch file 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? 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



Discussion

No Comment Found