Solved script:Change file name base on contain of text file

July 23, 2012 at 01:06:42
Specs: Windows XP
Hi All,
Need your help.
1. I have directory c:\Awal contain several text files. I need a script to move text files to other folder (C:\KECIL or C:\SEDANG or C:\BESAR). files move to C:\KECIL if the file contains word "kecil", move to C:\SEDANG for file containing word "sedang", and C:\BESAR for file contains word "besar".
2. when it move to folder, it will change file name to (kecil/sedang/besar)+currdate+currtime+.txt.
fyi. c:\Awal gets new files in minutes/hours so that it will more than 50-100 files a day. the script will be put on windows scheduler to let it automatically move.
Many thanks for your help.
Alex

See More: script:Change file name base on contain of text file

Report •

#1
July 23, 2012 at 19:41:21
(leaving date/time-stamp %dt% up to you for now...)
here is preliminary:
@echo off & setlocal
:temporary stand-in, reformat to suit:
set dt=%date%-%time%
for /f "tokens=1* delims=:" %%a in ('findstr /i /L /g:g1 *.txt') do (
for /f %%z in ('findstr "%%b" g1') do (
echo target aquired:%%z:
echo move "%%a" \%%z\%%z%dt%
)
)
:end
g1 content (any order the lines):
kecil
besar
sedang
------ end g1

Report •

#2
August 5, 2012 at 12:54:35
Hi nbrane,
what next?
thanks

Report •

#3
August 7, 2012 at 18:42:13
✔ Best Answer
Well, FIRST, apologies for my goofs. SECOND, here is code that might work. I tested on very small sample. Works the same way, basically, but less error-prone.

@echo off & setlocal enabledelayedexpansion
set dt=%date:~10%%date:~4,2%%date:~7,2%@%time%
for /f "tokens=*" %%a in (g1) do (
for /f "tokens=1* delims=:" %%b in ('findstr /i /L "%%a" *.txt') do (
echo SEARCHED STRING, A: %%a FOUND IN FILE, B: %%b
echo move "%%b" \%%a\%%a%dt%
)
)


Report •
Related Solutions


Ask Question