| View previous topic :: View next topic |
| Author |
Message |
flypaper Contributor


Joined: 19 Oct 2001 Posts: 104
|
Posted: Fri Sep 13, 2002 12:29 pm Post subject: Help point me in the right direction |
|
|
| I need to write a program to search and replace in filenames in a certain folder. Can someone give me some idea for this? How can I search for a filename, and then rename it? Sorry, seems a really dumb question. |
|
| Back to top |
|
 |
Protected Valued Contributor


Joined: 02 Jan 2001 Posts: 228 Location: Portugal
|
Posted: Fri Sep 13, 2002 12:34 pm Post subject: |
|
|
| Well, you can use LIST FILELIST to make a list with the files in a folder. Then you can either make a loop for the program to verify the items one by one, and then do the desired action (FILE command can replace filenames) or you can use @match() to search for the filenames you want to replace, and then rename them (a loop would be required too). |
|
| Back to top |
|
 |
LiquidCode Moderator Team
Joined: 05 Dec 2000 Posts: 1753 Location: Space and Time
|
Posted: Fri Sep 13, 2002 12:35 pm Post subject: |
|
|
You can create a list and then populate it with all the files
within the folder then repeat throught it and fine the file you
want. Something like this:
| Code: |
%%found =
%%file = autoexec.bat
List create,1
list filelist,1,C:\*.*
%x = 0
repeat
%i = @name(@item(1,%x)).@ext(@item(1,%x))
if @equal(%i,%%file)
%%found = 1
end
%x = @succ(%x)
until @equal(%x,@count(1))
if %%found
Info File Found!
end
|
_________________ Chris
Http://theblindhouse.com |
|
| Back to top |
|
 |
flypaper Contributor


Joined: 19 Oct 2001 Posts: 104
|
Posted: Fri Sep 13, 2002 12:49 pm Post subject: |
|
|
Thanks guys. Sometimes you just need someone to smack you in the face w/ the obvious.  |
|
| Back to top |
|
 |
Que Valued Newbie

Joined: 25 Aug 2001 Posts: 38 Location: Newaygo, MICH
|
Posted: Fri Sep 13, 2002 2:39 pm Post subject: |
|
|
Remember - Depending on how you are searching that @match only searches the list from the current record forward. Use list seek,listname,0
at the end of your repeat if you need to search the entire list each time.
| Quote: | @MATCH( <list>, <string> )
Description:
This function returns 1 (true) if a string in the string list <list>, starting from the current pointer position, contains text matching <string>.
Copyright 1995 - 2002 S.A.D.E. s.a.r.l. / All rights are reserved. |
_________________ Que |
|
| Back to top |
|
 |
Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Fri Sep 13, 2002 9:30 pm Post subject: |
|
|
| Que wrote: | Remember - Depending on how you are searching that @match only searches the list from the current record forward. Use list seek,listname,0
at the end of your repeat if you need to search the entire list each time.
|
Good point Que,
Also, if searching for the same string again, you must increment
the current index by one. Otherwise, @match() will continue to
find the current position if the string was found...
Cheers, Mac  _________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|
| Back to top |
|
 |
Protected Valued Contributor


Joined: 02 Jan 2001 Posts: 228 Location: Portugal
|
Posted: Fri Sep 13, 2002 9:35 pm Post subject: |
|
|
| When I use @match(), I simply copy all the contents to another list, then everytime it finds something I delete that thing, that way it never finds the same item twice... also after finding the item with @match() its possible to use @pos() to find the match inside the list item. But, anyway, I think using LIST SEEK or @item(x,y) to search all the list items one by one in a loop, is a much better way |
|
| Back to top |
|
 |
Tommy Admin Team
Joined: 16 Nov 2002 Posts: 746 Location: The Netherlands
|
Posted: Sat Sep 14, 2002 2:13 pm Post subject: |
|
|
| Protected wrote: | | But, anyway, I think using LIST SEEK or @item(x,y) to search all the list items one by one in a loop, is a much better way |
Of course using that in a loop will be much slower than simply using the @match() function. |
|
| Back to top |
|
 |
Garrett Moderator Team
Joined: 04 Oct 2001 Posts: 2149 Location: A House
|
Posted: Sat Sep 14, 2002 6:03 pm Post subject: |
|
|
Here's the problem with @match()..... Years ago I made a search
program and I used @match(). It works ok, but the problem is, if your
search string is contained within another word, it will also show up as a
result. Say you were searching for "Stan". @match() will find that and
any other words that have "Stan" in it, such as "Stands". Now to get
around this, if your list only contains one word in each item, you can
compare the resulting item and search string with @len(). If they both
have the same @len(), then it's a perfect match. But if each item in the
list contains more than one word, you'll have to do a bit of work to parse
that line to get the whole word and see if it does match or not.
-Garrett |
|
| Back to top |
|
 |
cnodnarb Professional Member


Joined: 11 Sep 2002 Posts: 766 Location: Eastman, GA
|
Posted: Sun Sep 15, 2002 12:28 am Post subject: |
|
|
I think the way to overcome the problem Garrett mentioned would be to include an extra space
%%match = @match(list1,"Stan ")
NodNarb |
|
| Back to top |
|
 |
Protected Valued Contributor


Joined: 02 Jan 2001 Posts: 228 Location: Portugal
|
Posted: Sun Sep 15, 2002 12:42 am Post subject: |
|
|
| Quote: | | Of course using that in a loop will be much slower than simply using the @match() function. |
I dont know... I dont trust @match(), at least examining every item you're sure it retrieves everything, even being slower |
|
| Back to top |
|
 |
moke Contributor

Joined: 02 Jan 2002 Posts: 162
|
Posted: Fri Sep 20, 2002 5:26 pm Post subject: |
|
|
| I don't trust it either, but i do use it. I don't know if it helps speed but i now try to use @ match to find the string then If @equal to verify it is what i want. It seemed like it might speed up things instead of checking every list item. |
|
| Back to top |
|
 |
|