Xenobiologist Posted March 9, 2006 Share Posted March 9, 2006 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. Only the FileCopy doesn´t work. Any Ideas? expandcollapse popup#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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 9, 2006 Share Posted March 9, 2006 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. 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! 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 Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 9, 2006 Author Share Posted March 9, 2006 (edited) Thanks PsaltyDS,hmmh, seems okay but the files are not renamed/copied. Maybe FileFindNextFile does not return a really file handle? So that this line: FileCopy($file2, StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx", 9)couldn´t "create" the file by coping. This seems correct: a) Debug Info $file2 = Matze_A-6.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-6(00'06"48).Replay.gbxa) Debug Info $file2 = Matze_A-7.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-7(00'10"15).Replay.gbxa) Debug Info $file2 = Matze_A-9.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-9(00'06"60).Replay.gbxa) Debug Info $file2 = Matze_G-8.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_G-8(00'31"21).Replay.gbxSo long,Mega Edited March 9, 2006 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 9, 2006 Share Posted March 9, 2006 (edited) Thanks PsaltyDS,hmmh, seems okay but the files are not renamed/copied. Maybe FileFindNextFile does not return a really file handle? So that this line: FileCopy($file2, StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx", 9)couldn´t "create" the file by coping. This seems correct: a) Debug Info $file2 = Matze_A-6.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-6(00'06"48).Replay.gbxa) Debug Info $file2 = Matze_A-7.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-7(00'10"15).Replay.gbxa) Debug Info $file2 = Matze_A-9.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_A-9(00'06"60).Replay.gbxa) Debug Info $file2 = Matze_G-8.Replay.txtb ) StringTrimRight(@ScriptDir & "\" & $newFileName, 3) & "gbx" = c) C:\Downloads\AutoIt-Skripte\Entwicklung\Rennspiel\Matze_G-8(00'31"21).Replay.gbxSo long,MegaEEK! 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. Edited March 9, 2006 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 Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 9, 2006 Author Share Posted March 9, 2006 (edited) EEK! 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. Yeah, as you said. I changed the ' and " which divided the time in min'sec"millisec into - and now it works perfectly. I have to try seperately, whether FileCopy cannot copy names with ' " in it. Thank you!So long,MegaDamn that took 2 hours!!! Edited March 9, 2006 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 Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 9, 2006 Author Share Posted March 9, 2006 Duh to me! I mixed up double quote " and two single quotes ''. That is way FileCopy couldn´t copy. 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now