Jump to content

File Create/Append...


StMaSi
 Share

Recommended Posts

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.

Link to comment
Share on other sites

Link to comment
Share on other sites

Here's exactly what's happening...

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

However, no file creation and no errors encountered.

Thanks again.

Link to comment
Share on other sites

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
Link to comment
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.

 

Link to comment
Share on other sites

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!!!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...