Automatic rename of text file to current date
-
Hello, @nuclearbinoculars, @scott-sumner and All,
Here is a method, using the NppExec plugin, a very powerful plugin, that you can download from, below :
https://github.com/d0vgan/nppexec/releases
I assume some hypotheses :
-
Your file is always named
MM-JJ-AAAA_TODO.txt
-
In the NppExec code, below, it is supposed to belong to a folder named “D:\AB CDE”. Of course, any pathname can be used instead, even if it contains spaces in name, as I surrounded it with double-quotes, in the code !
-
Your
MM-JJ-AAAA_TODO.txt
file must be unique in its folder ! I means no other file with name ending with _TODO.txt -
Note that, either,
-
the install directory of Notepad++.exe
-
The working directory of NppExec plugin
-
can be totally different from the location of your
MM-JJ-AAAA_TODO.txt
file
So :
-
Install the NppExec plugin, first
-
Open Notepad++
-
Select Plugins > NppExec > Execute… (
F6
)
Copy all the text, below, in the window of the <temporary script>
// START of the script npp_console off // Close the NPPEXEC CONSOLE window, if possibly OPENED npp_close _TODO.txt // Close the 'MM-JJ-AAAA_TODO.txt" N++ tab, if PRESENT npe_console v+ // Allows to store the OUTPUT CHILD process in NppExec variable $(OUTPUT) cmd /c dir /b "D:\AB CDE\*_TODO.txt" // Return the CURRENT name of a file, ending with "_TODO.txt" cmd /c rename "D:\AB CDE\$(OUTPUT)" %date:/=-%_TODO.txt // RENAME the NAME file with the CURRENT date, DASH separated, followed with "_TODO.txt" npe_console v- // Disable storing the OUTPUT of the NppExec CHILD process npp_open "D:\AB CDE\*_TODO.txt" // Open the file "MM-JJ+1-AAAA_TODO.txt" in a N++ NEW tab // END of the script
-
Everywhere the string “D:\ABC DE” occurs, just replace it, with the current location of your
MM-JJ-AAAA_TODO.txt
file -
Now, click on the OK button, to execute this temporary script
=> The
MM-JJ-AAAA_TODO.txt
tab, if it exists, disappears, and almost immediately, a new tab occurs, with name =MM-JJ
+1-AAAA_TODO.txt
, and same contents, due to an internal rename process ;-))-
Then, If result is as expected, click, on the Save… button and save this code as, let’s say,
ToDo
script -
Finally, choose the option Plugins > NppExec > Advanced Options…
-
In the right upper corner of that dialog, for the option Execute the script when Notepad++ starts:, select the
ToDo
script and click on the OK button
From now on, each time, you open Notepad++, you’ll see your TODO file, with current date, even if your start Notepad++ with the option
Notepad++ -nosession
, in a CMD console window ;-))Best Regards,
guy038
P.S. :
Of course, As I’m French, the true date format ( when using
echo %date%
in a CMD window ), isDD/MM/YYYY
but it should work correctly for any date format ! -
-
@Scott-Sumner Scott I’m not sure what else to tell you, or what more to explain. I just want my To Do List to have the current date resolved in the name every day…maybe i’m kinda anal about things like this. I tend to be overly organized a lot of the time >…<
-
(DOH, I had a 20 minute barrier for multiple responses, due to being a new user.)
@guy038 Guy, AWESOME!!! I just saw this, cool! I’m gonna follow your directions and see if I can get this sucker to work hehe.Thank you so much for that detailed and easy-to-follow method. I will attempt to implement it now.
-
Hi guy038.
I finally had time to ATTEMPT to implement the script you created. It is not working for me :(
I have pasted my edited version below:// START of the script
npp_console off // Close the NPPEXEC CONSOLE window, if possibly OPENED
npp_close _TODO.txt // Close the 'MM-JJ-AAAA_TODO.txt" N++ tab, if PRESENT
npe_console v+ // Allows to store the OUTPUT CHILD process in NppExec variable $(OUTPUT)
cmd /c dir /b “C:\Users\Jayce\Desktop*_TODO.txt” // Return the CURRENT name of a file, ending with “_TODO.txt”
cmd /c rename “C:\Users\Jayce\Desktop$(OUTPUT)” %date:/=-%_TODO.txt // RENAME the NAME file with the CURRENT date, DASH separated, followed with “_TODO.txt”
npe_console v- // Disable storing the OUTPUT of the NppExec CHILD process
npp_open “C:\Users\Jayce\Desktop*_TODO.txt” // Open the file “MM-JJ+1-AAAA_TODO.txt” in a N++ NEW tab
// END of the script
Notice, that I just temporarily changed the date a few days ahead to test the script, but when I use the echo command in cmd it DOES show my temporary changed date.
Can you take a look at the script text, and tell me if you see something that is not right? Maybe a permission issue? I keep my TODO list on my desktop for easier access.
Thank you so much for your time and help :)
-Jay
-
Hi, @nuclearbinoculars,
Could you tell me the result of the command
dir /b "C:\Users\Jayce\*_TODO.txt"
, on your system, after opening aCMD
console window ?Cheers,
guy038
-
@guy038 Hi again guy.
When I use dir /b “C:\Users\Jayce*_TODO.txt” from cmd, I get a File Not Found return.
When I use dir /b “C:\Users\Jayce\desktop*_TODO.txt” from cmd, I get 11-29-18_TODO.txt
I’m not sure what is going on? I think it should pick up the to do list with the * card even though the desktop is not specifically queried?
-
Hi, @nuclearbinoculars,
Sorry, I was mistaken, in my last post ! Indeed, I meant :
Could you tell me the result of the command
dir /b "C:\Users\Jayce\Desktop\*_TODO.txt"
, on … … …On the other hand, you said :
When I use dir /b “C:\Users\Jayce*_TODO.txt” from cmd, I get a File Not Found return.
When I use dir /b “C:\Users\Jayce\desktop*_TODO.txt” from cmd, I get 11-29-18_TODO.txt
I suppose that you wanted to mean :
When I use dir /b "C:\Users\Jayce\*_TODO.txt" from cmd, I get a File Not Found return. When I use dir /b "C:\Users\Jayce\desktop\*_TODO.txt" from cmd, I get 11-29-18_TODO.txt
with a reverse slash, (
\
) after Jayce and desktop, didn’t you ?
If so, just verify that, in your NppExec script, in
3
locations, that a reverse slash,\
, exists, right after the word Desktop !Best Regards,
guy038
-
As hints for posting in this forum:
There is a preview pane to the right, which will show how we will see your text. Please check it to make sure that what we will read will match what you intended. It makes it much easier if we don’t have to guess what your actual text was.
There is a little ? help icon in the editing pane while you are making your post, which explains this forum uses Markdown, and links to the official Markdown help. There’s also an excellent guide to Markdown in this forum, which gives something of a how-to/style-guide for posting here.
The Markdown processor in the forum treats certain characters and character-sequences as special (as described in those links). To avoid having the forum mangle your text, you can surround a piece of inline text with
`
(backtick or grave-accent) characters, which will also render the surrounded text in a red monospaced font: for example when @guy038 wrotedir /b "C:\Users\Jayce\Desktop\*_TODO.txt"
, he used the syntax`dir /b "C:\Users\Jayce\Desktop\*_TODO.txt"`
. If he had not, it would have rendered as dir /b “C:\Users\Jayce\Desktop*_TODO.txt” – notice how\*
gets collapsed to*
. The preview window shows you this.If you have multiple lines you want to be rendered without interpretation, you can either put a blank line before and after and indent every line by 4 spaces, or you can surround it by a line containing only ```z before and one containing only ``` after:
```z When I use dir /b "C:\Users\Jayce\*_TODO.txt" from cmd, I get a File Not Found return. When I use dir /b "C:\Users\Jayce\desktop\*_TODO.txt" from cmd, I get 11-29-18_TODO.txt ```
which will then render as
When I use dir /b "C:\Users\Jayce\*_TODO.txt" from cmd, I get a File Not Found return. When I use dir /b "C:\Users\Jayce\desktop\*_TODO.txt" from cmd, I get 11-29-18_TODO.txt
Hope this helps.
(I don’t have anything in the technical content to add, because @guy038 has done an excellent job of providing support. I just thought I’d help with the forum meta help, to make it easier to communicate your information to us.)
-
@guy038 Hi again and again guy :)
YEP, I thought you had meant to use the
dir /b "C:\Users\Jayce\desktop\*_TODO.txt" from cmd, I get 11-29-18_TODO.txt
Also, YEP, I DID mean to have a reverse slash after Jayce and desktop. For some reason it did not show up and my edit time had timed out.
OK, I will edit as you suggested and try again.
EDIT: Thank you PeterJones, I will try to use the proper syntax from now on…
-
@NuclearBinoculars said:
I DID mean to have a reverse slash…For some reason it did not show up
The reason is that you did not put your text inside proper delimiters (the ones that turn text shown here into a red-on-pinkish background, for example). If you had, it would not have consumed your backslashes. But with your most recent posting you seem to have mastered the delimiters technique, so I’ll say no more… :-)