Elgin Posted June 19, 2017 Posted June 19, 2017 I seemed to have run into a file name length limit of 22 characters. e.g., 18 plus 1 for "." and 3 for the extension: 18.3. This occurs when using FileMove to rename a file. The path length is short, but only the file length causes the the FileMove to fail without an error message. For example (file path remove for the example): temp file name: "temp.txt" new file name: "messages_2017-05-31.xml" This fails: FileMove("temp.txt", "messages_2017-05-31.xml", $FC_OVERWRITE) This succeeds: (removed the 1 from the day of the month) FileMove("temp.txt", "messages_2017-05-3.xml", $FC_OVERWRITE)
Developers Jos Posted June 19, 2017 Developers Posted June 19, 2017 This works fine for me in Win10/x64: #include <FileConstants.au3> $rc=FileWriteLine("temp.txt","test line") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $rc=FileMove("temp.txt", "messages_2017-05-31.xml", $FC_OVERWRITE) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console What is the information shown in your SciTE outputpane when ran from SciTE? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
jchd Posted June 19, 2017 Posted June 19, 2017 (edited) Must be an error in the actual code: #include <File.au3> #include <FileConstants.au3> #include <Array.au3> Local $f = _TempFile() FileWrite($f, "Hi folks!") Local $n = "This is a pretty long filename including the dreaded part messages_2017-05-31.extension" FileMove($f, $n, $FC_OVERWRITE) FileDelete($f) Local $a = _FileListToArray(".", "*.extension") _ArrayDisplay($a) FileDelete($n) Edited June 19, 2017 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Elgin Posted June 19, 2017 Author Posted June 19, 2017 36 minutes ago, Jos said: This works fine for me in Win10/x64: #include <FileConstants.au3> $rc=FileWriteLine("temp.txt","test line") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $rc=FileMove("temp.txt", "messages_2017-05-31.xml", $FC_OVERWRITE) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console What is the information shown in your SciTE outputpane when ran from SciTE? Jos >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3" /UserParams +>13:58:27 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\elgin.SPECTRUM\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\elgin.SPECTRUM\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3 +>13:58:27 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop +>13:58:27 AutoIt3.exe ended.rc:0 +>13:58:27 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.9212
Developers Jos Posted June 19, 2017 Developers Posted June 19, 2017 I don't see any of the ConsoleWrite() statement output. Are you running this with @RequireAdmin? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Elgin Posted June 19, 2017 Author Posted June 19, 2017 2 minutes ago, Jos said: I don't see any of the ConsoleWrite() statement output. Are you running this with @RequireAdmin? Jos Neither
Elgin Posted June 19, 2017 Author Posted June 19, 2017 Maybe it's related to the size of the file being manipulated. It's ~61k characters, but that's ony 30KB. Here's the rest of the code. It must be something in there: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=..\..\..\Network\AutoIT_scripts\unzipEikon.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; AutoIt Version: 3.7.3 #cs ---------------------------------------------------------------------------- Author: WeaponX Script Function: Recursive file search (string based) Notes: -Fastest thus far #ce ---------------------------------------------------------------------------- #include <array.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> $timestamp = TimerInit() $sImFolder="F:\IT Services\Projects\Projects_Current\IM Archives\test2\" ;~ $sImFolder="F:\Regulatory\IM_Archives\temp\" ;~ $sImFolder="F:\Regulatory\IM_Archives\" $7z="C:\Program Files\7-Zip\7z.exe" $sXsd='xsi:noNamespaceSchemaLocation="ContextCentricFile.xsd"' $Array = RecursiveFileSearch($sImFolder) MsgBox(0, "", (TimerDiff($timestamp) / 1000) & " seconds") ;0.0902s / 2090 files _ArrayDisplay($Array) Func RecursiveFileSearch($startDir, $depth = 0, $sParentDte="", $sParentFolder="") If $depth = 0 Then Global $RFSstring = "" $search = FileFindFirstFile($startDir & "\*.*") If @error Then Return ;Search through all files and folders in directory While 1 ;~ MsgBox(0,"", "depth: " & $depth) $next = FileFindNextFile($search) if $depth = 0 Then $sParentFolder=$next $sParentDte=StringLeft($next,10) ;~ MsgBox(0,"Top Parent: ","folder: " & $sParentFolder & ", " & $sParentDte) EndIf If @error Then ExitLoop EndIf ;If folder, recurse If StringInStr(FileGetAttrib($startDir & "\" & $next), "D") Then RecursiveFileSearch($startDir & "\" & $next, $depth + 1, $sParentDte, $sParentFolder) Else ;Append filename to master string $RFSstring &= $startDir & "\" & $next & "*" ;If is zip, then upzip $sExtension=StringTrimLeft($next, StringInStr($next, ".", 2, -1)) If $sExtension="zip" Then if $depth=2 then MsgBox(0,"Done", "Eikon Messenger files have been unzipped.") Exit EndIf $sSource = $sImFolder & $sParentFolder & "\messages" & "." & $sExtension $sDestinationPath = $sImFolder & $sParentFolder ;test for already unzipped $sSource_renameWpath = $sDestinationPath & "\messages.xml" $sDestination_renameWpath =$sDestinationPath & "\messages_" & $sParentDte & ".xml" $sTempFileWpath = $sDestinationPath & "\temp.txt" if FileExists($sDestination_renameWpath) Then ExitLoop ;begin unzip $iReturn = RunWait(@ComSpec & " /c " & "7z x " & '"' & $sSource & '"' & ' -o"' & $sDestinationPath & '"',"",@SW_HIDE) ;/c for close FileMove($sSource_renameWpath, $sDestination_renameWpath, 1) ;end upzip ;remove xsd reference FileOpen($sDestination_renameWpath) $sFileRead = FileRead($sDestination_renameWpath);contents of file $FileOpenTemp=FileOpen($sDestinationPath & "\temp.txt",$FO_APPEND);creates temp file $sString = StringReplace($sFileRead,$sXsd,"") ;write updated string to temp file FileWrite($FileOpenTemp,$sString) FileClose($FileOpenTemp) FileClose($sDestination_renameWpath) ;~ FileDelete($sDestination_renameWpath) ;rename destination file ConsoleWrite($FileOpenTemp & @CRLF) ConsoleWrite($sDestination_renameWpath & @CRLF) $rc=FileMove($sTempFileWpath, $sDestinationPath & "\messages_" & $sParentDte & ".xml", $FC_OVERWRITE) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Exit endIf EndIf WEnd FileClose($search) If $depth = 0 Then Return StringSplit(StringTrimRight($RFSstring, 1), "*") EndFunc ;==>RecursiveFileSearch
Elgin Posted June 19, 2017 Author Posted June 19, 2017 (edited) As you can see, no errors. It just doesn't rename the file. >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3" /UserParams +>15:25:31 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\elgin.SPECTRUM\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\elgin.SPECTRUM\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3 +>15:25:31 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop 4 F:\IT Services\Projects\Projects_Current\IM Archives\tst2\2017-05-31T0945+0000\messages_2017-05-31.xml @@ Debug(86) : $rc = 0 >Error code: 0 +>15:25:32 AutoIt3.exe ended.rc:0 +>15:25:32 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.09 Edited June 19, 2017 by JLogan3o13 Removed very long quote
Elgin Posted June 19, 2017 Author Posted June 19, 2017 Here's another angle of "no error, no rename" CODE: ;rename destination file ConsoleWrite($sTempFileWpath & @CRLF) ConsoleWrite($sDestinationPath & "\messages_" & $sParentDte & ".xml" & @CRLF) $rc=FileMove($sTempFileWpath, $sDestinationPath & "\messages_" & $sParentDte & ".xml", $FC_OVERWRITE) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $rc = ' & $rc & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Exit CONSOLE: >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3" /UserParams +>15:36:24 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00000409 OS:WIN_10/ CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\elgin.SPECTRUM\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\elgin.SPECTRUM\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Program Files (x86)\AutoIt3 input:F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3 +>15:36:24 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "F:\IT Services\Projects\Projects_Current\IM Archives\unzipEikon.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to StopF:\IT Services\Projects\Projects_Current\IM Archives\tst2\2017-05-31T0945+0000\temp.txt F:\IT Services\Projects\Projects_Current\IM Archives\tst2\2017-05-31T0945+0000\messages_2017-05-31.xml @@ Debug(86) : $rc = 0>Error code: 0 +>15:36:24 AutoIt3.exe ended.rc:0 +>15:36:24 AutoIt3Wrapper Finished. >Exit code: 0 Time: 1.013
Moderators JLogan3o13 Posted June 19, 2017 Moderators Posted June 19, 2017 @Elgin in the future, please just use the reply button rather than quoting previous posts. Especially for long output like you had above, it needlessly pads the thread. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Developers Jos Posted June 19, 2017 Developers Posted June 19, 2017 7 minutes ago, Elgin said: @@ Debug(86) : $rc = 0 This does mean that FileMove is unsuccessful which means it can't be moved. Could it be it is still open by another process or maybe an AV? ..or could does the targetfile already exists and in use? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Developers Jos Posted June 19, 2017 Developers Posted June 19, 2017 1 hour ago, Elgin said: FileOpen($sDestination_renameWpath) $sFileRead = FileRead($sDestination_renameWpath);contents of file This is by the way the wrong way of doing things. You are opening a file and not using the returned filehandle, which means the FileCLose() you have later in your script doesn't do anything either. Just the second line would be fine to read the whole file by using its name is fine, or else use the returned filehandle by the FileOpen() statement. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Elgin Posted June 22, 2017 Author Posted June 22, 2017 Jos Thanks. When I use the handle only, it worked. Elgin
TheSaint Posted September 18, 2017 Posted September 18, 2017 Just for the record, seeing as it is mentioned in the title topic, the file name or path length limit is set by Windows, and is still 260 characters all up I believe, though you can change a Policy setting in Windows 10 (and earlier??) to remove that limitation. An article to clarify Quote In Windows 10 (Version 1607 - Anniversary Update) and Windows Server 2016 you seem to have an option to ignore the MAX_PATH issue by overriding a group policy entry enable NTFS long paths under Computer Configuration -> Admin Templates -> System -> FileSystem: Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
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