Bagel Posted September 3, 2019 Posted September 3, 2019 I know I'm probably missing something simple and obvious here but I can't see what it is. I didn't see anything in the help file that could help me with this and I've seen similar examples working in other topics so I can't explain it. #include <Array.au3> #include <MsgBoxConstants.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include <Inet.au3> #Include <File.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <TrayConstants.au3> #include <Date.au3> $FileName = "C:\" & @YEAR & "-" & @MON & "-" & @MDAY & "-" & "TEST" & "-" & _DateTimeFormat(_NowCalc(), 5) & ".txt" ConsoleWrite ( $FileName ) $Variable = 6 $File = FileOpen($FileName, 1) FileWriteLine($File, "This is a test to see if I can write lines and variables to a text file... " & $Variable & @CRLF ) FileClose($File)
Subz Posted September 3, 2019 Posted September 3, 2019 Try adding #RequireAdmin to the top of the script maybe?
Nine Posted September 3, 2019 Posted September 3, 2019 #RequireAdmin is mandatory to write c:\. Also you can't use : inside file name. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Bagel Posted September 3, 2019 Author Posted September 3, 2019 I tried #RequireAdmin but also tried another directory on my desktop. The following works fine but using the original FileName with the date and times fails silently: #include <Array.au3> #include <MsgBoxConstants.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include <Inet.au3> #Include <File.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <TrayConstants.au3> #include <Date.au3> #RequireAdmin ;$FileName = "C:\" & @YEAR & "-" & @MON & "-" & @MDAY & "-" & "TEST" & "-" & _DateTimeFormat(_NowCalc(), 5) & ".txt" $FileName = "C:\TEST4.txt" ConsoleWrite ( $FileName ) $Variable = 6 $File = FileOpen($FileName, 1) FileWriteLine($File, "This is a test to see if I can write lines and variables to a text file... " & $Variable & @CRLF ) FileClose($File) I was able to create this on the desktop as well without RequireAdmin but can't see why the compound name fails. And that's what I need to work.
FrancescoDiMuro Posted September 3, 2019 Posted September 3, 2019 3 hours ago, Bagel said: but can't see why the compound name fails. Did you see what @Nine wrote? When you use _DateTimeFormat() and _NowCalc() functions, you are using a character that Windows doesn't allow in a filename. Could you please post what is returned if you try this? ConsoleWrite(_Now() & @CRLF) Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Bagel Posted September 3, 2019 Author Posted September 3, 2019 OH! Because of the format I selected for the date a while ago I didn't explicitly see that it was adding colons into the file name, saw the colon in the drive directory and noticed that it was working with one of my tests and didn't think anything more of it. Didn't help that FileOpen was failing silently. This is what I get for not stopping after getting burned out working on this project. Thanks! The following code works perfectly: #include <Array.au3> #include <MsgBoxConstants.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include <Inet.au3> #Include <File.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <TrayConstants.au3> #include <Date.au3> #RequireAdmin $FileName = "C:\" & @YEAR & "-" & @MON & "-" & @MDAY & "-" & "TEST" & "-" & StringReplace( _DateTimeFormat(_NowCalc(), 5) , ":", "-" ) & ".txt" $DateTest = StringReplace( _DateTimeFormat(_NowCalc(), 5) , ":", "-" ) ConsoleWrite ( $FileName & @CRLF ) $Variable = 6 $File = FileOpen($FileName, 1) FileWriteLine($File, "This is a test to see if I can write lines and variables to a text file... " & $Variable & @CRLF ) FileClose($File)
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