Sign in to follow this  
Followers 0
Nirvana6

Search inside non-text file

12 posts in this topic

Here is what i'm trying to do.

There is a file extension called. nif , 3d model/ mesh used in the game Oblivion.

now... when it's opened with Notepad , let's say, I get something like this :

ÿ>c?O"š¾pH³>h'?¬A¿«)—;›…¥>ÓEo¿¸ˆ¾\‚>Bw¿<±¼ˆ“Z?«Á*=×?þd?EÒ¼•œ‚½û…d¾Ã9x¿¦ê̽â™q?œöt>Ñ»i¾àño?#$ >HŠ¾yJ-?¦b<?:Å„¼p?ÌÑT?
y   =­3“>0u?aŽ¯»â:8<Ê>?Êq›=¨K?F¿J?†‘;€*>Šj{¿Ïz´=¢¦þ>÷
^¿àø¼-¾™å{¿É*i½ÏÄ>xri¿a龚Ž©>AÐl¿+~>¾å¦¶½2ú~¿ç¾;)k¿Ó>V¿^Å`=yÁ*¿êD>¿ñTT½Ÿ)k¿îʾ×9¢<Ü(?vï@?|Rå<‚,r?‚L >QM¬=ñb?€Ô̽rSç¾RØ¿¿<v~Ó<KT¿HU?Û=º<S¿H?Z\u½Â¾ ’l?Iè½4¡=Ù}?ÂuÒ="‘
>ís|?ŠÈ»=        ÿÿÿÿ                                      ÿÿÿÿ1   textures\characters\imperial\female\LegFemale.ddsÿÿÿÿ            Skin    ÿÿÿÿ  €?  €?  €?  €?  €?  €?  €?  €?  €?              ÈA  €?    ê  £SŸ?Ÿµƒ¿"ôLÂy¯†?ÊT?L]LÂTÏ?üžå?v\Â`m@¸…²¿˜Y^ÂÜ/7@.1ZÀ³¶HÂȧ@P
ŠÀ±–\Â]®@à|•À    MÂý õ@Ê ¢Àó?MÂUü@³ ÀY|^ÂïAÚÀp|MÂ6AèŽÀQ¯]ÂûM(A¿#À¦ªMÂ*1A%ÿÀ3
\Âoå@AžGM?EŸMÂûM(A¿#À¦ªMÂ*1A%ÿÀ3
\

more characters ....

then a texture path again : textures\characters\imperial\female\LegFemale.dds

and so on.

Now... I'm looking for a search method that will find the texture paths and save them in a .txt file.

The texture paths appear on different lines and not in a well defined position.

Thanks in advance.

Alex Valentine


Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe try something like this (I'm sure it probably could of been done better, but it seems to work)

Assuming all of these things your looking for start with "textures\":

Global $path
$Read = FileRead(@ScriptDir & "\File.txt")
$Position=StringInStr($Read,"textures\")
$test=StringMid($Read,$Position+9)
For $i = 0 To StringLen($test)
    $c=StringMid($test,$i+1,1)
    If StringIsAlpha($c) Or Asc($c) = 92 Or Asc($c) = 46 Then ; 46 = "." 92 = "\"
        $path &= $c
    Else
        ExitLoop
    EndIf
    If StringRight($path,4) = ".dds" Then ExitLoop
Next
MsgBox(0,"","textures\" & $path)
Edited by bill88

Share this post


Link to post
Share on other sites

thank you .

Seems it should work just fine.

Thanks a lot :)


Share this post


Link to post
Share on other sites

Tested it.

Now ... the problem is that the script will stop if it meets any numbers in the path .

So I'm wondering what condition I must change.

Oh .. and another question. What should i use to force the script look for another texture path in the same file ?

e.g :

characters ......

more characters Textures\path103.dds

characters again ...

---

---

textures\path205.dds.

E.g end.

Thank you in advance .

Alex Valentine.


Share this post


Link to post
Share on other sites

Now ... the problem is that the script will stop if it meets any numbers in the path .

So I'm wondering what condition I must change.

Try changing
StringIsAlpha($c)
to
StringIsAlNum($c)

Oh .. and another question. What should i use to force the script look for another texture path in the same file ?

Try putting the code for $Position and $test within your loop, making necessary adjustments to StringInStr 'occurrence' and 'start'.

I would do something like

$Read = StringReplace(FileRead(@ScriptDir & "\File.txt"), Chr(0), "")
and
$aTextures = StringRegExp($Read, '(?i)textures\\.*\.dds', 3)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

ok ...

#include<array.au3>
#Include <File.au3>

$FileList= _FileListToArray(@ScriptDir, "*.nif" , 1 )
_ArrayDisplay($FileList,"$FileList")


Global $path
Local $Array1[1]


For $i=0 to Ubound($FileList)-1

$Read = FileRead($FileList[$i])
$Position=StringInStr($Read,"textures\")
$test=StringMid($Read,$Position+9)
$A = _texsrc ()
_ArrayDisplay($Array1)

Next

func _texsrc ()

For $i = 0 To StringLen($test)
    $c=StringMid($test,$i+1,1)
    If StringIsAlNum($c) Or Asc($c) = 92 Or Asc($c) = 46 Then ; 46 = "." 92 = "\"
        $path &= $c
    Else
        ExitLoop
    EndIf
    If StringRight($path,4) = ".dds" Then ExitLoop
    Next
    _ArrayAdd ($Array1 , ("textures\" & $path))
Endfunc

the StringIsAlNum($c) worked like a charm , Thank you picaxe :)

I added an option to look in the script folder for all the .nif files

and a function to add the texture path into an array.

Unfortunately , I don't really understand what I must change in the script to

"Oh .. and another question. What should i use to force the script look for another texture path in the same file ? "

Sorry for that picaxe Edited by Nirvana6

Share this post


Link to post
Share on other sites

#include<array.au3>
#Include <File.au3>

$dumpfolder = InputBox ("Export Folder" , "Path" , @ScriptDir&"\")
$FileList= _FileListToArray(@ScriptDir, "*.nif" , 1 )



Global $path
Local $Array1[1] , $ArrayMesh [1]
$ind = 1
$Mesh = -1
$folder = InputBox ( "Textures Folder","Path" ,"E:\Games\Oblivion\bsacmd\out\txtrs\textures\")
$xind = InputBox ( "Textures Number" , "Number" , 5 )



For $i=0 to Ubound($FileList)-1
    $ind = 1
    $Mesh = $Mesh + 1
$Read = FileRead($FileList[$i])
while $ind < $xind

$Position=StringInStr($Read,"textures\",2 ,$ind)
$test=StringMid($Read,$Position+9)
$A = _texsrc ()
WEnd
Next


func _texsrc ()

For $i = 0 To StringLen($test)
    $c=StringMid($test,$i+1,1)
    If StringIsAlNum($c) Or Asc($c) = 92 Or Asc($c) = 46 Then ; 46 = "." 92 = "\"
        $path &= $c
    Else
        ExitLoop
    EndIf
    
    If StringRight($path,4) = ".dds" Then 
        ExitLoop
    Endif
    
Next

if $path <> "" then 
_ArrayAdd ($Array1 , ($folder&$path))
_ArrayAdd ($ArrayMesh ,($Mesh&"<->"&$folder&$path))
Endif
$ind= $ind+1
$path=''

Endfunc

For $j= 1 to Ubound($FileList)-1 
    DirCreate($dumpfolder&(StringTrimRight($FileList[$j],4)))
Next

For $k = 1 to Ubound($Array1) - 1 
    If FileExists ( ($Array1[$k])) = 1 Then
        FileCopy ( $Array1[$k] , @ScriptDir , 1 )
    EndIf
    Next

_ArrayDisplay($ArrayMesh,"Array Textures")

well... it's done :)

and i managed to avoid using :

$sTxt = FileRead(@ScriptDir & '\file.txt')
$aMatch = StringRegExp($sTxt, '(?i)(textures[\\\w.]*)', 3)

If IsArray($aMatch) Then _ArrayDisplay($aMatch)

Thank you , everyone .

This will be published as a free utility for Oblivion Modding .

If you want me to use other names than your current user names in the credits section , PM me. if not , I'll use those which are available. :)

Thank you again.

as a note ... is there a function or method to convert a displayed array as a txt file ?

The only way I'm aware of is creating an .ini file and write in it , but I'd like to avoid using sections ...


Share this post


Link to post
Share on other sites

... is there a function or method to convert a displayed array as a txt file ?The only way I'm aware of is creating an .ini file and write in it , but I'd like to avoid using sections ...

Something like
FileWrite(@Scriptdir & "\text.txt", _ArrayToString($ArrayMesh, @CRLF))

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Many thanks for the help.

I'm currently working on a small GUI interface for the script , and i bumped into this .

how can I open a file ?

Run ( @ScriptDir&"\NTE.ini") is not working - I'm aware that it only open executable files , but i tried anyway -

nor FileOpen.

Any ideas ?

Thank you ,

Alex Valentine

Edited by Nirvana6

Share this post


Link to post
Share on other sites

Many thanks for the help.

I'm currently working on a small GUI interface for the script , and i bumped into this .

how can I open a file ?

Run ( @ScriptDir&"\NTE.ini") is not working - I'm aware that it only open executable files , but i tried anyway -

nor FileOpen.

Any ideas ?

Thank you ,

Alex Valentine

ShellExecute( @ScriptDir & "\NTE.ini" )

[font=Microsoft Sans Serif]My Scripts: From Most recent to least.[/font]Countdown GUI | QLOCK TWO | FlipClock | Slot Machine My UDF:_GenerateRandomNoRepeat | _GuiSnap

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

thank you , bill :)

-snip-

It simply doesn't create any folders and doesn't move the textures in them .

It just creates the Exported.txt right .

Array1 it's empty - > should contain the textures paths

Solved. There were some incomplete paths , but now's ok.

Thank you :)

Edited by Nirvana6

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0