StMaSi

File Create/Append...

11 posts in this topic

I'm trying to create a file on a network share, from a Windows 10 computer, but for whatever reason, I'm unable to do so. The file just isn't created. In addition, if I manually create the file myself and simply try to append data to it, that doesn't work either. The network share in question is completely unrestricted and all domain users have full control.

Whether I use this to attempt to create a file...

_FileCreate('"' & @ScriptDir & '\filename.txt' & '"')

Or this to attempt to append to an existing file...

FileWriteLine('"' & @ScriptDir & '\filename.txt' & '"', "This is a test." & @CRLF)

Neither work.

Can anyone assist with this?

Thanks in advance.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use FileOpen function first with the flag set to 1 first for example:

$hFileOpen = FileOpen(@ScriptDir & '\Filename.txt', 9)
FileWrite($hFileOpen, 'This is a test')

 

Edited by Subz
Changed flag

Share this post


Link to post
Share on other sites

Yup, did that, but still no-go. Using FileOpen and FileClose before and after.

Thanks.

Share this post


Link to post
Share on other sites

Can you try the code above?

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You should run this code within Scite and you'll notice that you have errors in the naming.

Brain fade, should go to bed, this works for me on UNC using Windows 10 x64

#include <Date.au3>
$mdate = StringReplace(_NowCalcDate(), "/", "")
$mtime = StringReplace(_NowTime(5), ":", "")
$mfile = @ComputerName & "." & $mdate & "." & $mtime & ".txt"
ConsoleWrite($mfile & @CRLF)
$file = FileOpen(@ScriptDir & '\' & $mfile, 9)
FileWrite($file, "This is a test.")
FileClose($file)

 

Edited by Subz

Share this post


Link to post
Share on other sites

What is the path of the share?  Is it a mapped drive or UNC path?  If it's a mapped drive, are you elevating the script or using #RequireAdmin?

You should also check $file to make sure it actually returned the handle, else FileWrite and Close will fail.

 

Share this post


Link to post
Share on other sites

Updated my post above, the issue was the quotes you have around the filename, it was attempting to create the file '"ComputerName.Date.Time.txt"'.

Share this post


Link to post
Share on other sites

#10 ·  Posted

19 minutes ago, Subz said:

You should run this code within Scite and you'll notice that you have errors in the naming.

Brain fade, should go to bed, this works for me on UNC using Windows 10 x64

#include <Date.au3>
$mdate = StringReplace(_NowCalcDate(), "/", "")
$mtime = StringReplace(_NowTime(5), ":", "")
$mfile = @ComputerName & "." & $mdate & "." & $mtime & ".txt"
ConsoleWrite($mfile & @CRLF)
$file = FileOpen(@ScriptDir & '\' & $mfile, 9)
FileWrite($file, "This is a test.")
FileClose($file)

 

This worked!

Thank you very much!!!

Share this post


Link to post
Share on other sites

#11 ·  Posted

Before I go just wanted to point out you could use $mfile =  @ComputerName & '.' & @Year & @Mon & @MDay & '.' & @Hour & @Min & @Sec & '.txt'

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