Sign in to follow this  
Followers 0
ioliver

FileMove() Help

29 posts in this topic

Here's my code:

$output = FileOpen("C:\SearchIMF-Output.txt", 2); Opens for writing
$dir = InputBox("Search IMF for @microsoft.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")

$search = FileFindFirstFile("*.EML")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
   ; MsgBox(4096, "File:", $file); Uncomment to test script 
    
    $EML = FileOpen($file, 0)
   ; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
   ; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
       ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") <> 0 Then
            $x = 1
            If StringInStr($line, "@microsoft.com") <> 0 Then
               ; MsgBox(0, "Search IMF.au3 found an email from Microsoft", $file); Uncomment to test script
                FileWriteLine($output, $file)
                FileMove($file, $dir & "\xp\" & $file)
            EndIf
        EndIf           
        
    Wend
    
    FileClose($EML)
    
WEnd

FileClose($output)

I know that the script is working, partly, but it does not move the file to the XP directory that I created. Any ideas?

Thanks for your help,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites



I know that the script is working, partly, but it does not move the file to the XP directory that I created. Any ideas?

Thanks for your help,

Ian

you can't move a file that's still open, but your FileClose isn't until after the move

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

you can't move a file that's still open, but your FileClose isn't until after the move

Thanks cameronsdad, I thought that might be the problem. But, if I do a file close there will it effect my FileFindNextFile() ?

Thanks,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites

Thanks cameronsdad, I thought that might be the problem. But, if I do a file close there will it effect my FileFindNextFile() ?

Thanks,

Ian

no, because you'll be closing the $file instead of the $search

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I didnt wanted to make a new topic, so i post my problem here:

$folder = FileSelectFolder("Select folder where is mp3 files...", @ScriptDir)
$search = FileFindFirstFile($folder &"\*.*")
While 1
    $file = FileFindNextFile($search)
    If @error Then Exit
    If StringRight($file, 3) = "mp3" Then
        $name = $folder &"\" &$file
; Instantiate a COM instance with your new dll
$oId3 = ObjCreate("CDDBControl.CddbID3Tag")
; Load the tags from your specified file - they are now available in the form $oId3.TagName
$oId3.LoadFromFile ($name, True); True means open for read-only
; Copy tag information into variables
$sTitle = $oId3.Title
$sLeadArtist = $oId3.LeadArtist
FileMove($name, $folder &"\" &$sLeadArtist &" - " &$sTitle &".mp3")
EndIf
WEnd

This needs dll what you can download from here: http://www.helpy.com.ar/cen-dll/c.htm

This code should find mp3 file and rename it to its real name... But FileMove() is not working!

PS: Many thanks to DaleHohm for this .dll and code :P

Share this post


Link to post
Share on other sites

I didnt wanted to make a new topic, so i post my problem here:

$folder = FileSelectFolder("Select folder where is mp3 files...", @ScriptDir)
$search = FileFindFirstFile($folder &"\*.*")
While 1
    $file = FileFindNextFile($search)
    If @error Then Exit
    If StringRight($file, 3) = "mp3" Then
        $name = $folder &"\" &$file
; Instantiate a COM instance with your new dll
$oId3 = ObjCreate("CDDBControl.CddbID3Tag")
; Load the tags from your specified file - they are now available in the form $oId3.TagName
$oId3.LoadFromFile ($name, True); True means open for read-only
; Copy tag information into variables
$sTitle = $oId3.Title
$sLeadArtist = $oId3.LeadArtist
FileMove($name, $folder &"\" &$sLeadArtist &" - " &$sTitle &".mp3")
EndIf
WEnd

This needs dll what you can download from here: http://www.helpy.com.ar/cen-dll/c.htm

This code should find mp3 file and rename it to its real name... But FileMove() is not working!

PS: Many thanks to DaleHohm for this .dll and code :P

Looks like same type of problem

$oId3.LoadFromFile ($name, True); True means open for read-only


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

no, because you'll be closing the $file instead of the $search

camersonsdad, Here's the updated part of my code, but it errors out after it copies the first file...

; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
       ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") <> 0 Then
            $x = 1
            If StringInStr($line, "@xpsystems.com") <> 0 Then
               ; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $file); Uncomment to test script
                FileWriteLine($output, $file)
                FileClose($EML)
                FileMove($file, $dir & "\xp\" & $file)
                $EML = FileOpen($file)
            EndIf
        EndIf           
        
    Wend
    
    FileClose($EML)
    
WEnd

FileClose($output)

Thanks for the help,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites

Okey sorry about my bad english... I cant speak english very well... I want get ID3 tags from .mp3 file, and rename something like "01 - somesong" with FileMove() to "Artist from .mp3 file" &" - " &"Song name from .mp3 file".

Thanks!

Share this post


Link to post
Share on other sites

@ioliver, sorry about your thread being somewhat hijacked

@poisonkiller, don't the the proper calls to the dll your using, but loadfile opens the file, is there a closefile or something like it? if so you may need to do that 1st then rename.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

@ioliver, sorry about your thread being somewhat hijacked

@poisonkiller, don't the the proper calls to the dll your using, but loadfile opens the file, is there a closefile or something like it? if so you may need to do that 1st then rename.

@gafost, no problem. Got any ideas about my problem?

Thanks,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites

Here's the new thing I tired:

; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
       ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") <> 0 Then
            If StringInStr($line, "@xpsystems.com") <> 0 Then
               ; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $file); Uncomment to test script
                FileWriteLine($output, $file)
                FileClose($EML)
                FileMove($file, $dir & "\xp\" & $file)
                $x = 1
            EndIf
        EndIf           
        
    Wend
    
    If $x <> 1 Then
        FileClose($EML)
    EndIf
    
WEnd

FileClose($output)

Here's the error I got:

Search IMF.au3 (29) : ==> Invalid file handle used.:

$line = FileReadLine($EML)

Thanks,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites

Here's the new thing I tired:

; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
      ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") <> 0 Then
            If StringInStr($line, "@xpsystems.com") <> 0 Then
              ; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $file); Uncomment to test script
                FileWriteLine($output, $file)
                FileClose($EML)
                FileMove($file, $dir & "\xp\" & $file)
                $x = 1
            EndIf
        EndIf           
        
    Wend
    
    If $x <> 1 Then
        FileClose($EML)
    EndIf
    
WEnd

FileClose($output)

Here's the error I got:

Thanks,

Ian

move your if $x <> 1 above the Wend above it


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

@ioliver, sorry about your thread being somewhat hijacked

@poisonkiller, don't the the proper calls to the dll your using, but loadfile opens the file, is there a closefile or something like it? if so you may need to do that 1st then rename.

I dont know...:P I dont to nothing about .dll-s and reading .dll-s...

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

; Read in lines of text until the EOF is reached, or until "x-sender:" is found

While 1

$line = FileReadLine($EML)

If @error = -1 Then ExitLoop

; MsgBox(0, "Line read:", $line); Uncomment to test script

If StringInStr($line, "x-sender:") <> 0 Then

$x = 1

If StringInStr($line, "@xpsystems.com") <> 0 Then

; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $file); Uncomment to test script

FileWriteLine($output, $file)

FileClose($EML)

FileMove($file, $dir & "\xp\" & $file)

$EML = FileOpen($file)

EndIf

EndIf

Wend

FileClose($EML)

WEnd

FileClose($output)

the highlighted section is the issue. the $file still points at the file's original location, where it no longer exists after you move it. the second highlighted file tries to open the file that no longer exists. On the brights side it looks like you don't do anything with it after opening it again, so i'd just remove that line, and the second FileClose($EML) too.

***edit*** fixed the coloring of the lines i was talking about

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

What about using an ExitLoop(), like this:

; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
       ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") <> 0 Then
            If StringInStr($line, "@xpsystems.com") <> 0 Then
               ; MsgBox(0, "Search IMF.au3 found an email from XP Systems", $file); Uncomment to test script
                FileWriteLine($output, $file)
                FileClose($EML)
                FileMove($file, $dir & "\xp\" & $file)
               ;$x = 1
                ExitLoop(3)
            EndIf
        EndIf           
        
    Wend
    
   ;If $x <> 1 Then
        FileClose($EML)
   ;EndIf
    
WEnd

FileClose($output)

But I get this error:

Search IMF.au3 (39) : ==> "ExitLoop/ContinueLoop" statements only valid from inside a For/Do/While loop.:

ExitLoop(3)

Thanks,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites

But I get this error:

Thanks,

Ian

could you re-post a full listing of your script?

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

could you re-post a full listing of your script?

Sure. Thanks for your help with this. I've tried a couple of different things, but here's what I'm working with now:

$output = FileOpen("C:\SearchIMF-Output.txt", 2); Opens for writing
$dir = InputBox("Search IMF for @ms.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")

$search = FileFindFirstFile("*.EML")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
   ;$x = 0
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
   ; MsgBox(4096, "File:", $file); Uncomment to test script 
    
    $EML = FileOpen($file, 0)
   ; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
   ; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
       ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") <> 0 Then
            If StringInStr($line, "@ms.com") <> 0 Then
               ; MsgBox(0, "Search IMF.au3 found an email from ms", $file); Uncomment to test script
                FileWriteLine($output, $file)
                FileClose($EML)
                FileMove($file, $dir & "\xp\" & $file)
                $EML = FileOpen($dir & "\xp\" & $file)
               ;$x = 1
            EndIf
        EndIf           
    
       ;If $x = 1 Then ExitLoop
            
    Wend
    
    FileClose($EML)
        
WEnd

FileClose($output)

"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

Share this post


Link to post
Share on other sites

Sure. Thanks for your help with this. I've tried a couple of different things, but here's what I'm working with now:

$output = FileOpen("C:\SearchIMF-Output.txt", 2); Opens for writing
$dir = InputBox("Search IMF for @ms.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")

$search = FileFindFirstFile("*.EML")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
  ;$x = 0
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
  ; MsgBox(4096, "File:", $file); Uncomment to test script  
    
    $EML = FileOpen($file, 0)
  ; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    
  ; Read in lines of text until the EOF is reached, or until "x-sender:" is found
    While 1
        $line = FileReadLine($EML)
        If @error = -1 Then ExitLoop
      ; MsgBox(0, "Line read:", $line); Uncomment to test script
        If StringInStr($line, "x-sender:") <> 0 Then
            If StringInStr($line, "@ms.com") <> 0 Then
              ; MsgBox(0, "Search IMF.au3 found an email from ms", $file); Uncomment to test script
                FileWriteLine($output, $file)
                FileClose($EML)
                FileMove($file, $dir & "\xp\" & $file)
                $EML = FileOpen($dir & "\xp\" & $file)
              ;$x = 1
            EndIf
        EndIf           
    
      ;If $x = 1 Then ExitLoop
            
    Wend
    
    FileClose($EML)
        
WEnd

FileClose($output)
i'm still going through it, but one thing that jumps out at me is that you don't have an exit condition for your inner while loop.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i'm still going through it, but one thing that jumps out at me is that you don't have an exit condition for your inner while loop.

try this:

$output = FileOpen("C:\SearchIMF-Output.txt", 2); Opens for writing
$dir = InputBox("Search IMF for @ms.com", "Full Path to Directory:")
FileChangeDir($dir)
DirCreate($dir & "\xp")

$search = FileFindFirstFile("*.EML")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
;$x = 0
    $file = FileFindNextFile($search)
    
    If @error Then ExitLoop
; MsgBox(4096, "File:", $file); Uncomment to test script
    $EML = FileOpen($file, 0)
; Check if file opened for reading OK
    If $EML = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    $fc = FileRead($EML, FileGetSize($EML))
    If StringInStr($fc, "@ms.com") Then
        FileWriteLine($ouput, $file)
        FileClose($EML)
        FileMove($file, $dir & "\xp\" & $file)
;### Tidy Error: Level error -> WEnd is closing previous if
    WEnd
;### Tidy Error: Level error -> EndIf is closing previous While
EndIf

FileClose($output)

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

i'm still going through it, but one thing that jumps out at me is that you don't have an exit condition for your inner while loop.

I'd like for the 2nd to innermost loop to not run if it finds the word 'x-sender', but I didn't know how to code that. Is that what you mean by exit condition?

Thanks again,

Ian


"Blessed be the name of the Lord" - Job 1:21Check out Search IMF

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