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?
Use if in batch?
Re: Use if in batch?
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?
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?
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.
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?
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
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

)
I hope you like these examples. They would be great additions to TextCrawler
Re: Use if in batch?
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
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
-
- Posts: 2
- Joined: Fri Nov 22, 2013 5:47 am
Re: Use if in batch?
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
.
.
.
.
-----------------------------------------------
CORBIN GRAVELY
Best Schools in Oman
Last edited by corbingravely on Sat May 07, 2022 8:12 pm, edited 1 time in total.
- DigitalVolcano
- Site Admin
- Posts: 1863
- Joined: Thu Jun 09, 2011 10:04 am
Re: Use if in batch?
Points noted - The batch file processing for version 3.0 is being overhauled.