I'm trying to export a registry key with the current date as the name of the file using:
reg export "HKEY_CURRENT_USER\Network" "\\10.52.32.150\TimeMachine\PRETEND\%username%\%date%.reg"
But I receive "Error: The system was unable to find the specified registry key or value"
Why is this not working?
Thanks
%date% gives you the date in the locale you set. For me this is ISO 8601, i.e. YYYY-MM-DD, but in many other cases it's probably something insane, such as MM/DD/YY. Especially the latter case will make problems as the slash is likely not allowed there (or interpreted as hierarchy separator).
You can get the current date in a usable (and portable) form with WMI via
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined mydate set mydate=%%x
set mydate=%mydate:~0,8%
You then have the current date in YYYYMMDD form in %mydate%.
Related
I have a project with documentation written in ReStructuredText. The docs are compiled to HTML when the project is built via cmake. It includes a line with a "last changed" date.
I wonder how hard it would be to set this date automatically, as, from time to time, I simply forget to update the last changed date when I edit the docs.
I thought about generating some additional file, like
date -d "#$(stat -c %Z Readme.rst)" +"%d.%m.%Y" > lastchange.txt
and to reference it in the source like
:Date: .. include:: lastchange.txt
But would it be possible to achieve such a reference with only RST? Or in a more elegant way? Because doint it like so, it would be necessary to create a "working copy" of the sources in the cmake build directory, because otherwise the reference won't be found. And if I do this, I can as well sed the date into the sources directly.
How can I find out (with Windows a batch command), if, for example, a variable starts with ABC?
I know that I can search for variables if I know the whole content (if "%variable%"=="abc"), but I want that it only looks after the beginning.
I also need it to find out where the batch file is located, so if there is a other command that reveals the file's location, please let me know.
Use the variable substring syntax:
IF "%variable:~0,3%"=="ABC" [...]
If you need the path to the batch file without the batch file name, you can use the variable:
%~dp0
Syntax for this is explained in the help for the for command, although this variable syntax extends beyond just the for command syntax.
to find batch file location use %0 (gives full patch to current batch file) or %CD% variable which gives local directory
Okay, so I'm trying to make a program that "understands" user input and does what they tell it to do. People usually just use specific commands such as "open this file" and it only works if the user types EXACTLY that. I'm trying to give my users a little bit of leeway, so that they can type something like what they want to happen, and the computer will get the general idea. With that block of rambling aside, I've run into a problem.
set word%wordNum%=%word%
:fileExtension
set extChk= %letterNum% - 2 REM Includes the period of the extension
call set extension=%%_albaiRec:~%extChk%,4%%
::extChk is checking for a period so the program will recognize a file extension
set file=
That last line is where I get stuck...
I'm trying to use that last recorded word variable.
set var=7
set word7=Wanted text
echo %word%var%%
Sorta like that?
Add setLocal enableDelayedExpansion to the start of your script.
Then replace echo %word%var%% with echo !word%var%!.
For more information - http://ss64.com/nt/delayedexpansion.html
I would like to write a value to registry which consists of installation path and some additional path. Delimiter must be '/', e.g.
Value="[INSTALLLOCATION]/folder1/folder2"
How can I format this value so that installation path will be also with '/' delimiter instead of '\'?
MSI formatting doesn't support this. You'd have to write a custom action that read the property, reformatted the string and wrote it to a new property ( INSTALLLOCATIONFORMATTED) then you could use that property in the Registry table.
The bigger question and simpler answer though is .... "why?"
Are you doing something like file://c:/foo/bar.txt ?
file://C:\foo\bar.txt should work also as \ is the standard on the Windows Platform. It's probably better that whatever code reads this registry value be modified to accept \ instead of /. This results in a simpler and less fragile installer.
I'm in the process of writing a bash script (just learning it) which needs to find files in subdirectories created after a certain date. I have a folder /images/ with jpegs in various subfolders - I want to find all jpegs uploaded to that directory (or any subdirectories) after a certain date. I know about the -mtime flag, but my "last import" date is stored in %Y-%m-%d format and it'd be nice to use that if possible?
Also, each file/pathname will then be used to generate a MySQL SELECT query. I know find generally outputs the filenames found, line-by-line. But if find isn't actually the command that I should be using, it'd be nice to have a similar output format I could use to generate the SELECT query (WHERE image.file_name IN (...))
Try below script:
DATE=<<date>>
SEARCH_PATH=/images/
DATE=`echo $DATE|sed 's/-//g'`
DATE=$DATE"0000"
FILE=~/timecheck_${RANDOM}_$(date +"%Y%m%d%H%M")
touch -t $DATE $FILE
find $SEARCH_PATH -newer $FILE 2>/dev/null|awk 'BEGIN{f=0}{if(f==1)printf("\"%s\", ",l);l=$0;f=1}END{printf("\"%s\"",l)}'
rm -f $FILE
You can convert your date into the "last X days" format that find -mtime expects.
find is the correct command for this task. Send its output somewhere, then parse the file into the query.
Beware of SQL injection attacks if the files were uploaded by users. Beware of special-character quoting even if they weren't.