Jump to content
Sign in to follow this  
beserk1

FileFindFirstFile() wierd action

Recommended Posts

beserk1

Background info:

Files I am working with...

...
z078_000.jpeg ... z078_033.jpeg
z096_000.jpg ... z096_030.jpg
...

Part of code that is acting up.

$search_Page = FileFindFirstFile ( $stamp & _FrmtDgt ( $count_chap , $num ) & "*.*" )

$stamp is just the prefix of the files, in this case, "z"

_FrmtDgt( $normal, $digit ) is a recursive function that will add 0 before the $normal integer untill it reached the require $digit

Ex. _FrmtDgt( 78, 3 ) will return "078" and _FrmtDgt( 5, 6 ) will return "000005"

Problem:

I am trying to use FileFindFirstFile to scan for files that match a certain filter in a directory, in this case "z078_*", "z096_*" etc. However, when reaching to "z096_*", it studdenly went back to "z078_*".

More specificly,

096_000 > 078_008
096_001 > 078_009
096_002 > 078_007
098_000 > 078_018
098_001 > 078_019
098_002 > 078_016
098_003 > 078_017
098_004 > 078_014
098_005 > 078_015

where the left side is what it suppose to pick up, the right side is what is actually picking up. I have absolutly no idea why is only acting up on "078" and "096" and "098". This script has been used for over 10,000 files, and it has been working fine, only until now is been acting up and I have no idea why.

Can someone solve this mystery for me??

Edited by beserk1

Share this post


Link to post
Share on other sites
PsaltyDS

You are not showing the likely problem code.

I suspect the problem is with your _FrmtDgt() function. Why didn't you just use StringFormat()?

It could also be how you are using the search handle (you don't show any FileFindNextFile() calls).

Anyway, insert a debug function to show you what's being used, like:

$sTest = $stamp & _FrmtDgt($count_chap , $num) & "*.*"
ConsoleWrite("Debug: $sTest = " & $sTest & @LF)
$search_Page = FileFindFirstFile($sTest)

;...

$sResult = FileFindNextFile($search_Page)
ConsoleWrite("Debug: $sResult = " & $sResult & @LF)

;...

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
beserk1

Haha, I didn't know what to include.

It shouldn't be _FrmtDgt() function, since I have a debug function that is checking that out too.

Here, let me include more.

While 1
        
    $count_page = 1

    $search_Page = FileFindFirstFile ( $stamp & _FrmtDgt ( $count_chap , $num ) & "*.*" )
    If @error Then ExitLoop
    If $search_Page = -1 Then ExitLoop

    While 1
        $Page = FileFindNextFile ( $search_Page )
        If @error Then ExitLoop

        $file_ext = StringRight ( $Page , 4 )
        If $file_ext = ".jpg" Or $file_ext = ".png" Or $file_ext = ".jpeg" Or $file_ext = ".gif"  Then
            $PageNew = _FrmtDgt( $count_chap , 4 ) & "_" & _FrmtDgt( $count_page , 3 ) & StringLower ( $file_ext )
            $DirNew = $DirWorking & "\" & $FolderDone & "\" & $FolderComic & "\chap_" & _FrmtDgt( $count_chap , 4 )
            FileCopy ( $Page , $DirNew & "\" & $PageNew , 8 )
            $count_page += 1
        EndIf

        ;My debug function
        If $count_chap = 96 Or $count_chap = 98 Then
            MsgBox ( 4096, "Test", $stamp & @CR & _FrmtDgt ( $count_chap , $num ) & @CR & $Page & @CR & $file_ext & @CR & $PageNew & @CR & $DirNew )
        EndIf
    WEnd

    $count_chap += 1

WEnd

And the output of the debug MsgBox is:

$stamp = z
_FrmtDgt ( $count_chap , $num ) = 096
$Page = z078_008.jpeg
$file_ext = .jpeg
$PageNew = 0096_001.jpeg
$DirNew = C:\_\_comic\chap_0096
Edited by beserk1

Share this post


Link to post
Share on other sites
PsaltyDS

$file_ext = StringRight ( $Page , 4 )
        If $file_ext = ".jpg" Or $file_ext = ".png" Or $file_ext = ".jpeg" Or $file_ext = ".gif"  Then
            $PageNew = _FrmtDgt( $count_chap , 4 ) & "_" & _FrmtDgt( $count_page , 3 ) & StringLower ( $file_ext )
            $DirNew = $DirWorking & "\" & $FolderDone & "\" & $FolderComic & "\chap_" & _FrmtDgt( $count_chap , 4 )
            FileCopy ( $Page , $DirNew & "\" & $PageNew , 8 )
            $count_page += 1
        EndIfoÝ÷ Ûú®¢×zYr¢èZ½æ©®åzh^­æÞq«¬z«¨¶:^«¨¶+9r«iË^®Éè·­®)àF(!·Mú=¨ã¥åÊ­Ê­ç±µéìðØmçhµú+ky^¶×«{^ȨX¤z:`_¢¸ézáÉ¢p¢¹zÛ^­«­¢+Ø$$ÀÌØí¥±}áÐôMÑÉ¥¹I¥¡Ð ÀÌØíA°MÑÉ¥¹1¸ ÀÌØíA¤´MÑÉ¥¹%¹MÑÈ ÀÌØíA°ÅÕ½Ðì¸ÅÕ½Ðì°À°´Ä¤¬Ä¤

That will get the file extension, regardless of its length, for your compare.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
beserk1

Ah, damn! You are good, I thought I could've left out that part. =P Like you said, I did have problem with it. However I added a extra part to the If statment.

(seem like my goal for not flooding the thread with wall of code has failed =P )

...
ElseIf $file_ext = "jpeg" Then
    $file_ext = ".jpeg"
    $PageNew = _FrmtDgt( $count_chap , 4 ) & "_" & _FrmtDgt( $count_page , 3 ) & StringLower ( $file_ext )
    $DirNew = $DirWorking & "\" & $FolderDone & "\" & $FolderComic & "\chap_" & _FrmtDgt( $count_chap , 4 )
    FileCopy ( $Page , $DirNew & "\" & $PageNew , 8 )
    $count_page += 1
...

I dont think is the extentsion thats messing it up, if that were the case, the code I had post before will simply omit the jpeg extentsion.

But thanks for that bit of code you have, I been wanting to find a way to use the "." to scan for extentsion, but never got around to it. Thanks!

Share this post


Link to post
Share on other sites
beserk1

I still couldn't get it fix, can someone take a stab at it??

Share this post


Link to post
Share on other sites
PsaltyDS

I still couldn't get it fix, can someone take a stab at it??

Post a completely self-contained short reproducer script, with only as much code as is required to copy/paste into SciTE and hit F5 to see the issue.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
weaponx

Why are you using this:

_FrmtDgt( $count_chap , 4 )

When we have the builtin function:

;Will display 00001

$length = 5

MsgBox(0,"",StringFormat("%.0" & $length & "u", 1))

or just

MsgBox(0,"",StringFormat("%.05u", 1))

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.