batch-file

How to get standardized date/time stamp of file or dir. in pure batch scripting?

微笑、不失礼 提交于 2020-01-11 11:42:26
问题 Is there a way in Windows command line to retrieve the date/time stamps (modification, creation, access) of a file or directory in a standardized locale-independent format (for instance, ISO8601)? I found that the output of dir uses system-dependent date/time format, with the seconds missing. The same is true for the ~t modifier of the parameter ( %~t1 ) and for variable expansion ( %~tI ). Also the forfiles variables @fdate and @ftime depend on the system settings (although the latter

How to get standardized date/time stamp of file or dir. in pure batch scripting?

一世执手 提交于 2020-01-11 11:42:08
问题 Is there a way in Windows command line to retrieve the date/time stamps (modification, creation, access) of a file or directory in a standardized locale-independent format (for instance, ISO8601)? I found that the output of dir uses system-dependent date/time format, with the seconds missing. The same is true for the ~t modifier of the parameter ( %~t1 ) and for variable expansion ( %~tI ). Also the forfiles variables @fdate and @ftime depend on the system settings (although the latter

Find a line in a file and replace the next line

落爺英雄遲暮 提交于 2020-01-11 11:18:56
问题 Using a .bat script, I want to find a line that says # Site 1 and replace the text in the next line with a variable. I found tutorials on StackOverflow for finding and replacing a line, but not finding a line and replacing the next line. Any help? 回答1: @echo off set "the_file=C:\someFile" set "search_for=somestring" set "variable=http://site1" for /f "tokens=1 delims=:" %%# in ('findstr /n /c:"%search_for%" "%the_file%"') do ( set "line=%%#" goto :break ) :break set /a lineBefore=line-1 set

Find a line in a file and replace the next line

淺唱寂寞╮ 提交于 2020-01-11 11:18:03
问题 Using a .bat script, I want to find a line that says # Site 1 and replace the text in the next line with a variable. I found tutorials on StackOverflow for finding and replacing a line, but not finding a line and replacing the next line. Any help? 回答1: @echo off set "the_file=C:\someFile" set "search_for=somestring" set "variable=http://site1" for /f "tokens=1 delims=:" %%# in ('findstr /n /c:"%search_for%" "%the_file%"') do ( set "line=%%#" goto :break ) :break set /a lineBefore=line-1 set

Create a shortcut with parameters added to the program path

纵然是瞬间 提交于 2020-01-11 10:43:49
问题 Here's the code, it works if I right click on the new .Lnk and remove the quotes from "C:\Windows\System32\control.exe /name Microsoft.Windowsupdate" to C:\Windows\System32\control.exe /name Microsoft.Windowsupdate echo off Cls set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs" echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT% echo sLinkFile = "%USERPROFILE%\Desktop\Weekly Maintenance\Windows Update.lnk" >> %SCRIPT% echo Set oLink = oWS.CreateShortcut(sLinkFile) >>

Is it possible to change an .rtf file to .txt file using some sort of batch script on Windows?

和自甴很熟 提交于 2020-01-11 10:43:12
问题 We have a .rtf file that needs to be downloaded from a Windows machine, but it contains a lot of pictures in it so it is 2 GB. I would like to download just the text from this file, so it would be ideal if there was an automated script that ran each day on the Windows machine that could convert this file from rtf to txt. Is there a way to do this? 回答1: You can use unrtf. unrtf --text /path/to/rtf 回答2: Depending on your skill level, you can Use Office Automation to build a script in Word to

How to insert the output of a command to variable in a batch file?

一世执手 提交于 2020-01-11 10:42:15
问题 Inside a batch file on Windows I would like some variable to have the output of dir /b command. How this can be achieved ? 回答1: Batch files didn't handle this use case very well. I did find one thread that describes a technique using temporary files. 回答2: On Windows, there's a better facility that comes pre-installed. Its called vbscript (and later there is Powershell ). Why don't you use vbscript instead. strFolder="c:\test" Set objFS = CreateObject( "Scripting.FileSystemObject" ) Set

Create a shortcut with parameters added to the program path

柔情痞子 提交于 2020-01-11 10:42:10
问题 Here's the code, it works if I right click on the new .Lnk and remove the quotes from "C:\Windows\System32\control.exe /name Microsoft.Windowsupdate" to C:\Windows\System32\control.exe /name Microsoft.Windowsupdate echo off Cls set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs" echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT% echo sLinkFile = "%USERPROFILE%\Desktop\Weekly Maintenance\Windows Update.lnk" >> %SCRIPT% echo Set oLink = oWS.CreateShortcut(sLinkFile) >>

How to insert the output of a command to variable in a batch file?

感情迁移 提交于 2020-01-11 10:41:16
问题 Inside a batch file on Windows I would like some variable to have the output of dir /b command. How this can be achieved ? 回答1: Batch files didn't handle this use case very well. I did find one thread that describes a technique using temporary files. 回答2: On Windows, there's a better facility that comes pre-installed. Its called vbscript (and later there is Powershell ). Why don't you use vbscript instead. strFolder="c:\test" Set objFS = CreateObject( "Scripting.FileSystemObject" ) Set

New line as a delimeter of FOR loop

﹥>﹥吖頭↗ 提交于 2020-01-11 10:22:32
问题 I am new to batch script, and I am trying to parse a file that has key value (kind) of pairs delimited by new line. For example: the value of abc 1234 the value of def 5678 the value of ghi 9876 I would like to read this file using new line as delimited so that I can access the values. Something like for /f "tokens=1,2,3 delims='\n'" %%i in ('findstr /C:the value of abc 'filepath') do echo %%j 回答1: You can't set 'new line' as delimiter. Try this: @echo off &setlocal for /f "tokens=1*delims=:"