Skip to content

Please keep (the FileName part of) the original __SOURCE_FILE__ #25

@nodakai

Description

@nodakai

Sometimes it's convenient to be able to use Path.GetFileName __SOURCE_FILE__ for let's say a sender ID in logging.

let tempFile = Path.GetTempFileName()

Currently __SOURCE_FILE__ resolves to a random file path generated above. Is it possible to generate a temp directory containing a script file keeping the original name?

let mutable cnt = 0
let mutable stream = null
while (
  cnt <- cnt + 1
  if cnt = 100 then failwith "oh no"
  try 
      let p = Path.Join(Directory.CreateTempSubdirectory("fspack").FullName, Path.GetFileName fileName)
      stream <- new FileStream(p, FileMode.CreateNew, FileAccess.Write, FileShare.Read)
      false
  with :? IOException -> true
) do ()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions