Page 1 of 1
Use if in batch?
Posted: Tue Apr 24, 2012 3:22 pm
by aa
It would be nice to be able to add "if"s to batch files.
Example usage
if -> the file starts with <html
replace bla bla
if -> there is a specific word in the file
replace bla bla
Of course with the features of "if in if" "else if" etc.
What do you think?
Re: Use if in batch?
Posted: Tue Apr 24, 2012 3:25 pm
by aa
I need to replace thousands of files and want to exclude some of them which doesn't have the same structure as others. "If" would be nice for this need
Re: Use if in batch?
Posted: Tue Apr 24, 2012 10:51 pm
by Fool4UAnyway
If the numbers of check/find and replace actions isn't large, then you can perform those steps manually, by first searching the files that match your criteria and then execute the replace action on only those (selected and marked) files.
Re: Use if in batch?
Posted: Thu Apr 26, 2012 12:32 pm
by aa
There are workarounds for this issue, I could make a batch which could replace everything as expected automatically. But it was hard to create and takes too much time
also the "if feature" will greatly decrease the time consumed by the program. It will not look at all expressions, just the needed ones.
This way it's even possible to create batch files that with them you can replace too many different file types or same types - different structures just by adding some if's for each of them. Just one batch file = too many different jobs.
It's like the exclude option while searching files, but a better and effective solution
---------
I have another idea, please make possible to play with file names too.
For example {$filename} {$fileext} can be used to replace contents, any properties about the files can be added for this (maybe dates, metadatas, etc.)
An addition, maybe we should be able to rename the files by refering to the contents of them or by some numbers (file-1, file-2, text1, text2 etc.) using some kind of sorting.
Re: Use if in batch?
Posted: Thu Apr 26, 2012 1:05 pm
by aa
I just read this thread:
viewtopic.php?f=6&t=920, file filters looks like a good idea.
When using if, there would be two options, by file properties (date, etc.) or by code searches
And my extra suggestion is about "else if"
It's not necessary to separate different jobs but it would be nice when we need some "else"
An example:
If- the file contains the word "xyz" (
replace it with "zyx"
If - there is also a "abc" -> replace it with "bca"
else if - there is also "qwe" -> replace it with "ewq"
else - add some codes to beginning (For example: //This file doesn't contain any "abc" or "qwe")
)
else if - the {$fileext} is "html" or contains "htm" (
add {$filename} to the <title> and description tags
)
else if - the file is older than 1.1.2000 (
replace the file name as old-{$filename} (or sort and rename founded files as old-1, old-2 or rename them as {$filename}.{fileext}.old ...)
)
else (
"delete all codes inside the file

" or "delete the file" (a different idea) or "rename the file as junk-1, junk-2 and copy or move them to a folder named Junk or move them to Recycle Bin"
)
I hope you like these examples. They would be great additions to TextCrawler
Re: Use if in batch?
Posted: Fri Apr 27, 2012 11:57 pm
by zzz
"if not" can be added as well. same as "List files with no matches"
Re: Use if in batch?
Posted: Thu May 03, 2012 6:06 pm
by zzz
Ok, a better explanation:
Let's say there are thousands of files, every code in batch makes the process longer.
Normally, if the code is only in the 1% of files, I'll use the Find button (without any reg.exp. and using some simple words) and then mark all the founded files and then replace them.
But in the batch, it will take hours to do several jobs with regexps
Re: Use if in batch?
Posted: Fri Nov 22, 2013 6:59 am
by corbingravely
I have always felt the same way as well. I mean there are some commands that need to be repeated or looped. But the batch file coding is completely awful. Well the if’s might actually come in handy.
.
.
.
.
-----------------------------------------------
CORBIN GRAVELY
Best Schools in Oman
Re: Use if in batch?
Posted: Fri Nov 22, 2013 10:25 am
by DigitalVolcano
Points noted - The batch file processing for version 3.0 is being overhauled.