Sign in to follow this  
Followers 0
Xenobiologist

Why it doesn´t FileCopy?

6 posts in this topic

Hi,

I have a gbx file which I rename to txt files, read some data from it and then I want to rename the file and save it back.

Everything seems to work, although it is a strange code. :o

Only the FileCopy doesn´t work.

Any Ideas?

#include<string.au3>
#include <file.au3>
Dim $file1 = ""
Dim $file2 = ""
Dim $search1 = ""
Dim $search2 = ""
Dim $time = ""
#cs
    If $CmdLine[0] > 0 And $CmdLine[1] = "choose" Then
    
    $file = FileOpenDialog("Wähle die Datei:", @ScriptDir, "Replays (*.gbx)", 1 + 2 + 4, "")
    If @error Then
    MsgBox(4096, "", "No File(s) chosen")
    EndIf
    EndIf
#ce
; Shows the filenames of all gbx.files in the current directory.
$search1 = FileFindFirstFile("*.gbx")
; Check if the search was successful
If $search1 = -1 Then
    MsgBox(0, "Error", "No *.gbx files found!")
    Exit
EndIf

While 1
    $file1 = FileFindNextFile($search1)
    If @error Then ExitLoop
    saveAsTxt()
WEnd
FileClose($search1)

rename()
FileDelete(@ScriptDir & "\*.replay.txt")
Exit (0)

Func rename()
    $search2 = FileFindFirstFile("*.txt")
    While 1
        $file2 = FileFindNextFile($search2)
        If @error Then ExitLoop
        If StringInStr($file2, "(") = 0 Then
            $time = _StringBetween(FileRead($file2, FileGetSize($file2)), 'times best="', '" respawns')
            $time = StringTrimRight($time, 1)
        ;Aufbereitung Zeit
            $len = StringLen($time)
            Select
                Case $len <= 2
                    $time = _StringInsert ($time, "00'00" & '"', 0)
                Case $len = 3
                    $time = _StringInsert ($time, "00'0", 0)
                    $time = _StringInsert ($time, '"', -2)
                Case $len = 4
                    $time = _StringInsert ($time, "00'", 0)
                    $time = _StringInsert ($time, '"', -2)
                Case $len = 5
                    $rest = Mod(StringMid($time, 1, 3), 60)
                    $min = Int((StringMid($time, 1, 3) - $rest) / 60)
                    Select
                        Case $rest < 10 And $min < 10
                            $time = "0" & $min & "'" & "0" & $rest & '"' & StringRight($time, 2)
                        Case $rest > 10 And $min < 10
                            $time = "0" & $min & "'" & $rest & '"' & StringRight($time, 2)
                        Case $rest < 10 And $min > 10
                            $time = $min & "'" & "0" & $rest & '"' & StringRight($time, 2)
                        Case $rest > 10 And $min > 10
                            $time = $min & "'" & $rest & '"' & StringRight($time, 2)
                    EndSelect
            EndSelect
                $newFileName = _StringInsert ($file2, "(" & $time & ")", -11)
                FileCopy($file2, StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx", 9)
; ****************  THIS DOESN`T WORK****************
        EndIf
    WEnd
FileClose($search2)
EndFunc  ;==>rename

Func saveAsTxt()
    FileCopy($file1, StringTrimRight($file1, 3) & "txt")
EndFunc  ;==>saveAsTxt 

Func _StringBetween($s, $from, $to)
    $x = StringInStr($s, $from) + StringLen($from)
    $y = StringInStr(StringTrimLeft($s, $x), $to)
    Return StringMid($s, $x, $y)
EndFunc  ;==>_StringBetween

Thanks!

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites



Hi,

I have a gbx file which I rename to txt files, read some data from it and then I want to rename the file and save it back.

Everything seems to work, although it is a strange code. :o

Only the FileCopy doesn´t work.

Any Ideas?

To diagnose, change the line:

FileCopy($file2, StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx", 9)

To:

MsgBox(64, 'Debug Info', '$file2 = ' & $file2 & @CRLF & _
     'StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = ' & StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx")

That will tell you if it is evaluating as expected. Hope that helps! :geek:


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

#3 ·  Posted (edited)

Thanks PsaltyDS,

hmmh, seems okay but the files are not renamed/copied. Maybe FileFindNextFile does not return a really file handle? :o

So that this line:

FileCopy($file2, StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx", 9)

couldn´t "create" the file by coping. ;)

This seems correct: :geek:

a) Debug Info $file2 = Matze_A-6.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-6(00'06"48).Replay.gbx

a) Debug Info $file2 = Matze_A-7.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-7(00'10"15).Replay.gbx

a) Debug Info $file2 = Matze_A-9.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-9(00'06"60).Replay.gbx

a) Debug Info $file2 = Matze_G-8.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_G-8(00'31"21).Replay.gbx

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks PsaltyDS,

hmmh, seems okay but the files are not renamed/copied. Maybe FileFindNextFile does not return a really file handle? :geek:

So that this line:

FileCopy($file2, StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx", 9)

couldn´t "create" the file by coping. :huggles:

This seems correct: ;)

a) Debug Info $file2 = Matze_A-6.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-6(00'06"48).Replay.gbx

a) Debug Info $file2 = Matze_A-7.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-7(00'10"15).Replay.gbx

a) Debug Info $file2 = Matze_A-9.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-9(00'06"60).Replay.gbx

a) Debug Info $file2 = Matze_G-8.Replay.txt

b ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" =

c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_G-8(00'31"21).Replay.gbx

So long,

Mega

EEK! :o

You might be getting some pain from those LAT/LONG coordinates (or whatever they are) with both a single and a double quote buried in the file name! Just for giggles, manualy copy a couple of those to new file names like: Matze_G-8(00-31-21).Replay.gbx so as to get rid of those funky quotes in the file name. See if that changes things. If so, you might have to escape those characters somehow. :sorcerer:

P.S. FileFindNextFile() only returns a file path\name, not a handle. A file handle is for an Open file, which probably can't be copied while it's open, though I have never tested it.

Edited by PsaltyDS

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

#5 ·  Posted (edited)

EEK! :geek:

You might be getting some pain from those LAT/LONG coordinates (or whatever they are) with both a single and a double quote buried in the file name! Just for giggles, manualy copy a couple of those to new file names like: Matze_G-8(00-31-21).Replay.gbx so as to get rid of those funky quotes in the file name. See if that changes things. If so, you might have to escape those characters somehow. ;)

P.S. FileFindNextFile() only returns a file path\name, not a handle. A file handle is for an Open file, which probably can't be copied while it's open, though I have never tested it.

:sorcerer: Yeah, as you said. I changed the ' and " which divided the time in min'sec"millisec into - and now it works perfectly. :huggles:

I have to try seperately, whether FileCopy cannot copy names with ' " in it. :o

Thank you!

So long,

Mega

Damn that took 2 hours!!!

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Duh to me! :geek:

I mixed up double quote " and two single quotes ''.

That is way FileCopy couldn´t copy. :o

Anyhow, thanks for your help, again.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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