# Quining, but with Windows files!

Write a quine, that when run, creates itself in the current directory, in a source file named itself. We will be using Windows in this, so the file name (and therefore quine) must have the following limitations:

• None of these characters \ / : ? * < > |
• Fewer than 211 255 characters

### Limitations and assumptions

• Your code must be a full program (It's going to be run after all).

• No copying from the source file.

• You can assume that there isn't another file with your Quine as its name (as it would produce Quine (1)).

• Errors are allowed (as long as they don't get into the source code

This is , shortest code in bytes wins!

### Edit

Maybe I wasn't clear, the file with the name of the quine has to actually contain the quine. My bad.

• What are the limitations on non-ASCII characters in the program? (On Windows, this might quite possibly depend on what language version of Windows is installed; I forget the exact rules and whether they've changed over time.) – user62131 Feb 7 '17 at 15:11
• Why fewer than 211 bytes? That's kind of an arbitrary restriction... – mbomb007 Feb 7 '17 at 19:19
• @mbomb007 Max filename size, I believe. – Addison Crump Feb 7 '17 at 19:20
• @VoteToClose It's 255. stackoverflow.com/a/265782/2415524 – mbomb007 Feb 7 '17 at 19:22
• @mbomb007 Typo, perhaps? – Addison Crump Feb 7 '17 at 19:23

# Vitsy, 10 27 bytes

'rddd++&"rdd8++a[v}v1-D);].


If : was allowed, I could shorten this to 11 bytes. :(

Explanation:

'rddd++&"rdd8++a[v}v1-D);].
'                           Capture all instructions as a string until encountering
' again, looping if necessary.
r                          Reverse the current stack (output is top-down).
ddd++                     Push char literal ' to the stack.
&                    Push a new stack to the stack stack.
"                   Same as ', but " specific.
r                  Reverse the current stack.
dd8++             Push char literal " to the stack.
a            Push 10 to the stack.
[        ]  Loop forever.
v          Capture the top value as a variable.
}         Take the bottom item of the stack and put it on the top.
v        Dump the variable to the stack.
1-      Subtract 1.
D     Duplicate the top item.
);   Pop n; if n is 0, exit the loop.
a[v v1-D);]  This is a makeshift for loop with 10 iterations.
. Pop the top stack as n, and the second stack as o.
Write a file called "n" with the contents of "o".


The two stacks will be identical at the end. On some Java versions, this may throw a FileNotFoundException due to different implementations of the FileInputStream class.

&'rddd++}.


Explanation:

&           Push a new stack to the stack stack.
'rddd++    Modified standard quine.
}   Move the ' to the right place.
.  Pop the top stack as n, and the second stack as o. Write a file called
"n" with the contents of "o". (Quine name, no content)


Because I might as well, here's a diagram of the steps that occur within the stacks (each stack is represented by []):

Initial state: [[]]

&              [[], []]
Push a new stack to the stack stack.

'             [[], ["r", "d", "d", "d", "+", "+", "}", ".", "&"]]
This stack state occurs because ' will loop around the line
until finding the next '.

r            [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r"]]
Reverses the top (last) stack.

ddd         [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r", 13, 13, 13]
Push thirteen thrice.

++       [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r", "'"]
Because char ' is 39 = 13 + 13 + 13.

}      [[], [".", "}", "+", "+", "d", "d", "d", "r", "'", "&"]]
Takes the bottom item, then puts it on the top.

.     []
Writes a file with content from the second-to-top stack and the
name as the concatenation of all elements in the top stack,
with top member priority (backwards from my representation).


I'm actually not sure how this works right; minute changes cause this to break. For example, placing the & in various other locations should work just as well, but it causes ClassCastExceptions, IOExceptions, and ArrayOutOfBoundsExceptions depending on where you put it. I might need to do some bugfixing.

• +1 for Push a new stack to the stack stack. – Pavel Feb 7 '17 at 20:46
• +1 from me if you can push a new stack stack to a stack stack stack, otherwise forget it! ... Kidding +1, I laughed too. – Magic Octopus Urn Feb 7 '17 at 22:04
• @carusocomputing What if I told you I can with o? ;) – Addison Crump Feb 7 '17 at 22:04
• Sigh unzip... – Magic Octopus Urn Feb 7 '17 at 22:07
• Uhm... I think that the generated file is supposed to contain the code (i.e. its content should be equal to its filename) – Leo Feb 7 '17 at 22:41

# Node.js, 56 52 bytes

function f(){require('fs').writeFile(f+='f()',f)}f()


This prints the warning

DeprecationWarning: Calling an asynchronous function without callback is deprecated.

If you want the all-green, it costs 4 bytes to change writeFile to writeFileSync.

# Lua, 96 bytes.

s="s=%qs=string.format(s,s)f=io.open(s)f.write(f,s)"s=string.format(s,s)f=io.open(s)f.write(f,s)


Typed this on my phone, should work, but I'll test it when I get to a computer.

• I think at the very least you'll need to change sting.format to string.format twice. – Peter Taylor Feb 7 '17 at 8:28
• @PeterTaylor you don't like Sting, do you? – KeyWeeUsr Feb 7 '17 at 14:08
• @KeyWeeUsr, I have nothing against him personally, and in fact he helped pay for my upbringing, but I think that the Lua standard library was probably designed for general usability by people familiar with similar APIs rather than specifically for Police fans. – Peter Taylor Feb 7 '17 at 14:54

# C, 134 bytes

s[255];fd;char p[255]="s[255];fd;char p[255]=%c%s%c;main(){sprintf(s,p,34,p,34);creat(s,0);}";main(){sprintf(s,p,34,p,34);creat(s,0);}

• The source here contains * so it doesn't look like it's allowed according to the rules. – Value Ink May 23 '17 at 22:57
• @ValueInk Fixed. Thanks for pointing that out! – MD XF May 23 '17 at 23:10