Post by lod on Dec 17, 2018 13:14:32 GMT -5
Hi, I have typed several utilities in Liberty Basic thanks to the help I found here. Lastly I've been learnt to use the instr instruction and it's very useful.
I wrote this mass file renamer with instr. It's a true utility, isn't it ?
[start]
if path$="" then
'will have buttons that say OPEN and CANCEL:
filedialog "Open text file", "*.txt", fileName$
'print "File chosen is ";fileName$
dim cnt$(10)
a=0
token$ = "*"
parseMe$ = fileName$
'print "parseMe$="+parseMe$
idx = 0
while token$<>""
idx = idx + 1
token$ = word$(parseMe$, idx, "\")
if token$ <> "" then
' print "token$";idx;"="+token$
cnt$(idx-1)=token$
a=a+1
end if
wend
path$=""
for i=0 to a-2
if i>0 then
path$=path$+"\"
end if
path$=path$+cnt$(i)
next i
else
end if
'you must predimension the array info$(),
'even though FILES will
'redimension it to fit the information it provides.
dim info$(10, 10)
files path$, info$()
print path$
input "Chercher la chaïne:"; nb$
input "Remplacer par :"; e$
n=eval(info$(0, 0))
cl=len(nb$)
b=0
for i=1 to n
'print info$(0, 2)+info$(0, 3)+info$(i, 0)
word$=info$(i, 0)
'print word$
'c=instr(word$,nb$)
'print c
if instr(word$,nb$)>0 then
'print word$
b=b+1
clw=len(word$)
c=instr(word$,nb$)
d$=mid$(word$,0, c)
f$=mid$(word$,c+cl, clw)
rootFileName$=info$(0, 2)+info$(0, 3)+info$(i, 0)
'print d$+e$+f$
new$=d$+e$+f$
new$=info$(0, 2)+info$(0, 3)+new$
name rootFileName$ as new$
end if
next i
print b;" files renamed"
input "Continuer? y/n"; yn$
if yn$="y" or yn$="" then
input "Continuer dans le même dossier ? y/n"; fold$
if fold$="n" then
path$=""
end if
goto [start]
else
print "Closing time"
end
end if
wait
I wrote this mass file renamer with instr. It's a true utility, isn't it ?
[start]
if path$="" then
'will have buttons that say OPEN and CANCEL:
filedialog "Open text file", "*.txt", fileName$
'print "File chosen is ";fileName$
dim cnt$(10)
a=0
token$ = "*"
parseMe$ = fileName$
'print "parseMe$="+parseMe$
idx = 0
while token$<>""
idx = idx + 1
token$ = word$(parseMe$, idx, "\")
if token$ <> "" then
' print "token$";idx;"="+token$
cnt$(idx-1)=token$
a=a+1
end if
wend
path$=""
for i=0 to a-2
if i>0 then
path$=path$+"\"
end if
path$=path$+cnt$(i)
next i
else
end if
'you must predimension the array info$(),
'even though FILES will
'redimension it to fit the information it provides.
dim info$(10, 10)
files path$, info$()
print path$
input "Chercher la chaïne:"; nb$
input "Remplacer par :"; e$
n=eval(info$(0, 0))
cl=len(nb$)
b=0
for i=1 to n
'print info$(0, 2)+info$(0, 3)+info$(i, 0)
word$=info$(i, 0)
'print word$
'c=instr(word$,nb$)
'print c
if instr(word$,nb$)>0 then
'print word$
b=b+1
clw=len(word$)
c=instr(word$,nb$)
d$=mid$(word$,0, c)
f$=mid$(word$,c+cl, clw)
rootFileName$=info$(0, 2)+info$(0, 3)+info$(i, 0)
'print d$+e$+f$
new$=d$+e$+f$
new$=info$(0, 2)+info$(0, 3)+new$
name rootFileName$ as new$
end if
next i
print b;" files renamed"
input "Continuer? y/n"; yn$
if yn$="y" or yn$="" then
input "Continuer dans le même dossier ? y/n"; fold$
if fold$="n" then
path$=""
end if
goto [start]
else
print "Closing time"
end
end if
wait