I have what I think will be a one-time need to code in Powershell. I hope someone here can help me with the last bit of code to make my dream come true.
It would help my daily work to have a simple (semi-)manual backup procedure that allows me to:
Right-click any file and click an option in the menu to make a copy of that file in a subfolder (named _backup) with a timestamp appended to the filename.
… I have managed to make the copy and append timestamp work with the following code imported as a .reg-file as a registry entry:
//START of CODE
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\CopyAppendDate]
@=“Copy and Append Date”
[HKEY_CLASSES_ROOT\AllFilesystemObjects\shell\CopyAppendDate\Command]
@=“PowerShell.exe -WindowStyle Hidden -Command \”( Get-Item -LiteralPath ‘%1’ ) | %%{ Copy-Item -LiteralPath $.FullName -Destination ( ‘{0} {1:yyyy-MM-dd_HH.mm.ss}{2}’ -f $.BaseName, $.LastWriteTime, $.Extension ) }\“”
//END of CODE (a few \ is removed by the system here, but I hope it’s readable anyway)
I have tried adding .\_backup in various positions and with/without backslash, quotation marks, etc. but with no luck.
How do I refer to a specific subfolder in the code (and ideally create it, if it doesn’t exist already)?
suppose you save the script in “c:\shared tools\backupfile.ps1”. Then, in the registry, you can have something simpler :
powershell -NoLogo -ExecutionPolicy Bypass -command “& ‘c:\shared tools\backupfile.ps1’ -file ‘%1’”
and this give the registry file :
Thanks a lot. It works. However, not until I manually copy the command line into the command field in the registry. Initially after importing, it’s empty (value not set).
Any simple explanation for that?