|
Answer» I need to create a batch file to search the CONTEXT of the file (the file will be in different name and folder each time but will be in the same parent directory) and move that file to a folder if the file contains the constant sentence. Can anyone help? Please :-?It very difficult to design a batch file if the target file keeps CHANGING it's name and location. Is there a way to derive the file name, say from the date, time, maybe even longitude and latitude?
This little snippet bypasses the file name issue and lets the user take responsibility for entering the file name correctly:
Code: [Select]@echo off set /p F=Enter File Name: find /i "[highlight]constant sentence[/highlight]" %f% if not errorlevel 1 move %f% [highlight]newfolder[/highlight]
Be sure to change the highlighted text for your environment.
8-)Unfortunately, the file name is not able to control on our end Finally the light bulb went on:
Code: [Select]for /f "tokens=1* delims=" %%i in ('dir /a:-d /b /s [highlight]parentdirectory[/highlight]') do ( find /i "[highlight]constant sentence[/highlight]" "%%i" > nul if not errorlevel 1 move "%%i" [highlight]newfolder[/highlight] )
Change the highlighted FIELDS to match your environment.
Good luck. 8-)The solution is cool. I have ANOTHER question to ask for help, if we want to get some substring from a file, what should I do ? say in a file, i have one line, id : 100 I want to set the value 100 to a variable, how to do it ? Currently, I am using DOS6.22 shell, which does not support "FOR /F" command to read a file in.
|