Skip to content

Commit 2143c6c

Browse files
committed
Add filename.ext overwrite as second argument
1 parent 5746622 commit 2143c6c

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

PasteIntoFile/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void Main(string[] args)
7474
return;
7575
}
7676

77-
Application.Run(new frmMain(args[0]));
77+
Application.Run(new frmMain(args[0], args.Length > 1 ? args[1] : null));
7878
}
7979
else
8080
{

PasteIntoFile/frmMain.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public partial class frmMain : Form
2020
private string text;
2121
private Image image;
2222

23-
public frmMain(string location = null)
23+
public frmMain(string location = null, string filename = null)
2424
{
2525
location = location ?? @Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
2626

@@ -70,7 +70,7 @@ public frmMain(string location = null)
7070
comExt.Items.AddRange(new object[] {
7171
"bat", "java", "js", "json", "cpp", "cs", "css", "csv", "html", "php", "ps1", "py", "txt"
7272
});
73-
comExt.Text = Settings.Default.extensionText ?? "txt";
73+
comExt.Text = Settings.Default.extensionText == null ? "txt" : Settings.Default.extensionText;
7474

7575
}
7676
else if (Clipboard.ContainsImage())
@@ -87,6 +87,22 @@ public frmMain(string location = null)
8787

8888
}
8989

90+
// second parameter can overwrite filename and -type
91+
if (filename != null)
92+
{
93+
var i = filename.LastIndexOf('.');
94+
if (i < 0)
95+
{
96+
txtFilename.Text = filename;
97+
}
98+
else
99+
{
100+
txtFilename.Text = filename.Substring(0, i);
101+
comExt.Text = filename.Substring(i+1);
102+
}
103+
}
104+
105+
90106
// Pressed shift key resets autosave option
91107
if (ModifierKeys == Keys.Shift)
92108
{

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ See [all contributors](https://github.com/eltos/PasteIntoFile/graphs/contributor
3737

3838
_Tested on Windows 10_
3939

40-
## Configuration
40+
## Command Line Use
4141

4242
Run the following commands in a terminal (Command Prompt or PowerShell).
4343
- To add the *Paste Into File* entry in the File Explorer context menu:
@@ -48,9 +48,13 @@ Run the following commands in a terminal (Command Prompt or PowerShell).
4848
```powershell
4949
PasteIntoFile /unreg
5050
```
51-
- To change the default filename format:
51+
- To configure the default filename template format (see [format specifiers](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings)):
5252
```powershell
53-
PasteIntoFile /filename yyyyMMdd_HHmmss
54-
```
55-
For more information on the format specifiers, see [Custom date and time format strings](https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings).
53+
PasteIntoFile /filename "yyyy-MM-dd HH-mm-ss"
54+
```
55+
- To explicitly set the target path (and optionally also filename) once:
56+
```powershell
57+
PasteIntoFile \path\to\directory [filename.ext]
58+
```
59+
5660

0 commit comments

Comments
 (0)