change a certain string in filename (windows batch loop, wildcard) - windows

I have a ogr2ogr command and I am mixing the command with windows shell command
I have to loop through certain extensions only, which is *.shp. And, the command below is where I started
for %f in (*.shp) do (ogr2ogr .....
but now I have to loop through files with this kind of name.
road_node_1.shp
road_node_2.shp
...
road_node_9.shp
I played around with many types of wildcard such as
for %f in (road_node_*) do (ogr2ogr .....
then it loops through all the files that are related to the *.shp and the file name (without the extension) is same
road_node_1.shx
road_node_1.dbf
road_node_1.cpg
road_node_1.prj..
so It does go though unnecessary files, which takes more time to do process
I tried the command below and doesn't work either
for %f in (road_node_*.shp) do (ogr2ogr .....
I wonder if there is a way to loop through file names like that.

#Aacini
This is weird...
the command did not work a few hours ago
for %f in (road_node_*.shp) do
now... this command works like a magic.
I do not know what has been changed though issue solved :(

Related

Inkscape ungroup everything from windows command line

I converted a bunch of PDFs into individual SVGs for editing. The SVGs are named as the page numbers, so I have a whole folder of 001.svg, 002.svg ... and the problem is they all the objects in each SVG are grouped together and I have ungroup everything before I can edit the pages which takes a few minutes on each page.
Would save some time if I could ungroup all the pages from the command line first. I've looked at the inkscape command line options and maybe this is actually a windows command prompt or powershell question too because I'm not sure how to loop through files incrementally in either of those
I saw some question here for ungrouping from the command line with
inkscape --actions "select-all:groups; SelectionUnGroup; export-filename: output.svg; export-plain-svg; export-do;" intput.svg
But even trying that one individual files nothing happens, I did replace inkscape with the full path
Anyone know how to accomplish this? Thanks!
There should be an easier way by using the 'deep ungroup' Python script from the command line.
Unfortunately, I can only give you the syntax for Linux, so you need to adjust the paths and the '>' (which means 'output into the following file') to your Windows paths and PowerShell syntax.
With default extension settings, it works like so:
python3 /usr/share/inkscape/extensions/ungroup_deep.py groups.svg > ungrouped.svg
Alright I believe I have solved it. For some reason I don't think it's possible to do this using the "without-gui" flag which is unfortunate. But this is what I ended up using (still takes a few minutes per file, but doesn't require any work on my part"
I'm using Inkscape 0.92 for reference (I believe this would not work in later versions)
#echo off
for %%i in ("%~dp0*.svg") do (
echo %%i
"C:\Program Files\Inkscape\inkscape.exe" -f "%%i" --verb EditSelectAll --verb
SelectionUnGroup --verb FileSave --verb FileQuit
)

My batch files (.cmd) sometimes execute partial lines

I've a strange problem that I have never seen before in my ~30 years of working with batch files. Given a dummy CMD file such as this:
#echo off
:somelabel
echo Testing something
dir /b
echo All is well.
:end
This mostly runs as expected, but sometimes I get output such as 'ing something' is not recognized as an internal or external command, operable program or batch file.
That's clearly an occurrence where it has chopped off a bit of a line and attempted to execute the rest of it. When this happens, it's always a 'random' fraction of a 'random' line; it's not always line X, or losing Y characters, or occurring where I have a particular character combination. Nor does it affect only echo statements, it could just as well try to execute abel or ir /b.
My system is a fully updated Win2008 R2, running in VirtualBox 5.0.2, running in a fully upgraded Linux Mint, running on a Lenovo ThinkPad. The scripts are all UTF-8 encoded.
... what's going on? How can I avoid this?
Well, in my experience there is no way that a normal Batch file may present this behavior. The only way this can happen is if the Batch file is modified while it is running, so the cmd.exe processor continue reading the "next line" of the Batch file, but at that position in the modified file there is a part of another line. The example below show this behavior:
#echo off
:somelabel
(for /F "skip=1 delims=" %%a in (%~NX0) do echo %%a) > temp.tmp
del "%~NX0" & ren temp.tmp "%~NX0"
echo Testing something
echo All is well.
:end
In this example after the del ... & ren ... line is executed, the next line to execute will be read at the beginning of original position of echo Testing something line, but now at that point there is its ing something part because the first #echo off line was deleted. See this:
#echo offRL
echo Testing something
In previous scheme the RL letters exemplify the CR+LF control characters, so the next position is at the "ing".
Credit goes to #SomethingDark for the comment:
The command line doesn't play nice with UTF-8. Use ANSI instead.
This seems to have resolved the issue (as far as I can be sure with an intermittent problem).
I know this is a couple years late but I actually found the most accurate answer.
I actually did some testing on why it could register only partial code and got the answer. If you are editing the code and run batch while still open, it has a partial chance of only registering partial code. This is actually correct, nothing with encoding although that might be part of it except still does it to me with ANSI but with some testing, I realize that isn't it and that it is because batch cannot catch up with you when editing the code.
I did type a comment on the answer marked as best and said what I think but after further testing on the question I realized the pattern is when editing the code and running the batch file while still open, almost right away it seems to only read partial code.
When you said it seems to work when changing encoding to ANSI, did you just run it or did you edit it and run it at the same time. The main reason I did want to answer this is because my encoding method on a batch file I am working on is in ANSI and still causes the error of partially reading the code. Once I read Aacini answer, it gave me a thought of it and that he is partially correct to KlaymenDK situation.
Do prevent the error of partially reading the code modify and wait a bit than run and if that doesn't work than restart it. If you are planning on publicly posting it, you don't really have to worry about the problem because it would most likely only occur if you edit the code while running it. Nothing that could really be a problem with your code as I know.
Recently I run into the same problem, although the cause might be different.
In my case there was an REM command with text which have special characters in other languange. After I erased the REM command, the problem was solved.
For disclosure the problem did not happened in all computers the code was executed, and still dont know why will special characters cause the batch file to execute partial lines.

Listing the files inside a folder using batch file

I am using a batch file to view the contents (xml files) of a certain folder.
I need to use a batch file for it.
Found this command on internet and it is working perfectly when I type in the command prompt, but when I type it in and save as a batch file, it doesn't give any out put at all. (Basically not running the content)
FOR /R D:\Myfolder %F in (*.*) do rename %~nF.xml %~nf1.xml
There are no restrictions in the folder either.
Shouldn't have worked from the prompt.
In a batch file, you need to change any % for the metavariable (%F in this case) to %%.
Having said that however, (or, from the prompt, %F and %f) are two different animals. It's virtually the only situation where batch is case-sensitive. Your command attempts to rename files using their NAME only (~nF) so if it was to encounter fred.txt it would attempt to rename Fred.xml to -er, 1.xml (I think, maybe %~nf.xml)
Best to say what you're trying to do. We're reasonably slick at crufting up solutions...

Easy task, windows prompt batch file

I am a Windows 7 User who wants to convert multiple *.eps files to pdf-files. Therefore I installed a program called EPSPDF.rb.
I integrated it into my systempath which makes me use it in the command prompt like this:
C:\TEMP>epspdf somefile.eps
The program converts somefile.eps to somefile.pdf.
What I am trying to achieve now is writing a Windows Batch File which will look in
the directory C:\TEMP for all *.eps files and convert them all.
I am still trying hard since I am quite unfamiliar with the programming language.
I guess writing the few lines will be an easy issue for someone who is familiar with Batch Files in Windows. I will be very grateful for any help!
for %%f in (*.eps) do epspfd %%f
This is for use in a batch file. You can run it right on the command prompt, only you need to use %f instead of %%f. Just because. ;)
for %F in (*.eps) do epspdf %F

Windows Batch Script: For ... in loop to capture program output not working

I have a batch script setup to automatically retrieve a file from a remote FTP server. Part of the requirement is the file will be named with a new datestamp each day, such as "File_90611.csv." I have a command line tool that generates the filename; which is then supposed to be set to a variable using the line below:
for /f "delims=" %a in ('C:\BIN\YesterdayDateStamp.exe') do #set DATESTAMP=%a
The problem is this. This line works fine when run from the command line directly. However, when I put this exact same line in a batch script and run it; I get this error:
\BIN\YesterdayDateStamp.exe') was unexpected at this time.
I REM'ed everything out in the script except the FOR ... IN commands to make sure there wasn't some sort of conflict; but even with this I still get an error.
Been Googling for an answer but have no leads. Any ideas? Any constructive input is greatly appreciated.
Thanks,
Frank
When for is used in a batch file, you need to double the percent signs in front of the variable name.
From for /?:
To use the FOR command in a batch program, specify %%variable instead
of %variable. Variable names are case sensitive, so %i is different
from %I.

Resources