我正在使用Windows命令行环境编写批处理文件脚本,并希望将文件中某些文本(例如"FOO")的每次出现更改为另一个(例如"BAR").最简单的方法是什么?任何内置功能?
我可以用math.round舍入到x的小数位数,但有没有办法绕小数点左边?例如,如果我指定2个位置,则5变为05
在JavaScript中对值进行zerofill的推荐方法是什么?我想我可以构建一个自定义函数来将零填充到一个类型化的值,但我想知道是否有更直接的方法来做到这一点?
注意: "zerofilled"是指数据库中的单词意义(数字5的6位零填充表示为"000005").
Windows批处理文件有哪些鲜为人知但又重要且有用的功能?
指南:
澄清:我们在这里指的是由cmd.exe处理的脚本,这是WinNT变体的默认值.
(另请参阅:Windows批处理文件:.bat vs .cmd?)
我想将PDF转换为SVG,请建议一些能够有效执行此操作的库/可执行文件.我使用apache PDFBox和Batik库编写了自己的java程序 -
PDDocument document = PDDocument.load( pdfFile );
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document svgDocument = domImpl.createDocument(svgNS, "svg", null);
SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(svgDocument);
ctx.setEmbeddedFontsOn(true);
// Ask the test to render into the SVG Graphics2D implementation.
for(int i = 0 ; i < document.getNumberOfPages() ; i++){
String svgFName = svgDir+"page"+i+".svg";
(new File(svgFName)).createNewFile();
// Create an instance of the SVG Generator.
SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx,false);
Printable page = document.getPrintable(i);
page.print(svgGenerator, document.getPageFormat(i), …Run Code Online (Sandbox Code Playgroud) 我尝试用Ghostscript拆分多页PDF,我在更多网站甚至ghostscript.com上找到了相同的解决方案,即:
gs -sDEVICE=pdfwrite -dSAFER -o outname.%d.pdf input.pdf
Run Code Online (Sandbox Code Playgroud)
但它似乎对我不起作用,因为它生成一个文件,包含所有页面,名称为outname.1.pdf.
当我添加起始页和结束页时,它工作正常,但我希望它在不知道这些参数的情况下工作.
在gs-devel存档中,我找到了一个解决方案:http:
//ghostscript.com/pipermail/gs-devel/2009-April/008310.html - 但我觉得没有这样做pdf_info.
例如pswrite,当我使用不同的设备但是相同的参数时,它可以正常工作,产生尽可能多的ps文件,就像我的
input.pdf所包含的那样.
使用时这是正常的pdfwrite吗?难道我做错了什么?
我试图从XML标记访问和更改特定属性
XML:
<office>
<staff branch="Hanover" Type="sales">
<employee>
<Name>Tobias Weltner</Name>
<function>management</function>
<age>39</age>
</employee>
<employee>
<Name>Cofi Heidecke</Name>
<function>security</function>
<age>4</age>
</employee>
</staff>
<staff branch="London" Type="Technology">
<employee>
<Name>XXXX</Name>
<function>gement</function>
<age>39</age>
Run Code Online (Sandbox Code Playgroud)
从上面的例子我想打印分支属性,然后想要在所有整个XML中使用一个值(如纽约)更改它,并使用下面的代码来执行该操作
$xml=New-Object XML
$xml.Load("C:\FE6Work.xml")
$node=$xml.SelectNodes("/office/staff")
write-output $node.branch
$node.branch="New York"
Run Code Online (Sandbox Code Playgroud)
但得到一个错误说明无法找到该元素.
有人可以帮忙吗?
我正在尝试编写一个批处理脚本,该脚本可以获取(除其他外)计算机所有磁盘驱动器的列表.基本代码看起来像这样:
REM Build the list of disk drives to monitor
SETLOCAL enabledelayedexpansion
FOR /f "skip=1 tokens=1 delims=:" %%a in ('"WMIC logicaldisk WHERE drivetype=3 GET deviceid"') do (
SET "DISK_DATABASES=!DISK_DATABASES!%%a|"
SET "DRIVES_TO_MONITOR=!DRIVES_TO_MONITOR!%%a:\\|"
)
Run Code Online (Sandbox Code Playgroud)
我显然构建了两个格式略有不同的列表供以后使用.然而,当我运行它时,我得到的输出看起来像这样:
C|D|E||
C:\\|D:\\|E:\\|:\\|
Run Code Online (Sandbox Code Playgroud)
现在,我希望两种情况下的尾随管道都可以管理,但我真的很困惑,为什么还有一个额外的空白条目.如果我wmic手动运行命令,我可以看到输出结尾确实有一个空行,但我的理解是/f特别应该忽略空行.
如果我打开ECHO,看起来最后一行只是作为回车/换行符或类似物进入.有没有办法做我期待的事情?我错过了什么吗?我试图if在循环中写一个条件来排除最后一行,但它是......时髦而且从未奏效.我感谢任何/所有的帮助.
所以我有一个 .exe.config 文件,我试图在其中搜索特定属性,然后在 Windows 7 中使用 Powershell 4.0 版对其进行编辑,但我遇到了问题。我尝试了几件事,但没有任何成功。这是我正在使用的配置文件的精简版本。
<configuration>
<Config1>
<section name="text" type="text, text, text=text" allowLocation="true" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" requirePermission="true" />
</Config1>
<Config2>
<module debugLogLevel="Debug" Version="1.0.0.0" />
<Interested-Item attribute-1="text-text" attribute2="0">
</Interested-Item>
<modules>
<add name="something1" />
<add name="something2" />
<add name="something3" />
<add name="something4" />
<add name="something5" />
<add name="something6" />
<add name="something7" />
</modules>
</Config2>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我将如何使用 Powershell 更改感兴趣的项目下的属性 1?任何帮助将不胜感激。
下面是一些我尝试失败的例子。
$File = Get-Content $FileLocation
$XML = [XML]$File
foreach ($attribute in $XML.Config2.Interested-Item)
{
$attribute = Interested-Item.attribute-1 = "Updated Texted" …Run Code Online (Sandbox Code Playgroud) 我有一个简单的测试SVG,使用两个安装的字体(Helvetica-Narrow和Helvetica-Bold):
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="50">
<text x="0" y="24" fill="blue" font-family="Helvetica-Bold" font-size="24px">Bold</text>
<text x="0" y="48" fill="blue" font-family="Helvetica-Narrow" font-size="24px">Narrow</text>
</svg>
Run Code Online (Sandbox Code Playgroud)
如果我使用ImageMagick(在CentOS Linux 7(Core)上运行的ImageMagick 7.0.2-0 Q16 x86_64)将其转换为PDF文件,则结果不会使用已安装的字体.
例如:
$ convert -density 600 test.svg test.pdf
Run Code Online (Sandbox Code Playgroud)
产量:
看起来ImageMagick默认使用的是正常权重Helvetica,它与输入SVG中指定的任何字体系列都不匹配.
接下来,我尝试指定输入SVG中指定的其中一种字体的路径.这是Helvetica-Bold通过运行确定的字体路径convert -list font.
$ convert -density 600 -font /net/module/sw/ghostscript-fonts/5.50-32/n019004l.pfb test-helvetica-mix.svg test-helvetica-mix-bold.pdf
Run Code Online (Sandbox Code Playgroud)
第一个<text>元素是正确的 - 它使用Helvetica-Bold.第二个<text>元素是不正确的 - 它也使用Helvetica-Bold,但应该真正使用Helvetica-Narrow.
不过,我越来越接近这种方法了,所以我尝试将路径添加到输入SVG中使用的第二种字体:
$ convert -density 600 -font /net/module/sw/ghostscript-fonts/5.50-32/n019004l.pfb -font /net/module/sw/ghostscript-fonts/5.50-32/n019043l.pfb test-helvetica-mix.svg …Run Code Online (Sandbox Code Playgroud) 我有一个包含多个标签的XML文件,我试图用批处理脚本更改其中一个标签的内容.
xml文件的一个示例是:
<ConfigurationData>
<ReportsFolder>\Reports</ReportsFolder>
<Helpfolder>\Help</HelpFolder>
<InstallationType>Terminal</InstallationType>
<LicenseFolder>..\License</LicenseFolder>
</ConfigurationData>
Run Code Online (Sandbox Code Playgroud)
我试图改变之间的数据<InstallationType>和</InstallationType>我的选择的另一个变量.我想我需要某种For循环来找到xml文件的那一部分,但是我对如何编辑那一部分感到很遗憾.
batch-file ×4
windows ×3
javascript ×2
pdf ×2
powershell ×2
svg ×2
xml ×2
batik ×1
command-line ×1
fonts ×1
ghostscript ×1
imagemagick ×1
pdfbox ×1
scripting ×1
text-files ×1
types ×1
zerofill ×1