Search found 26 matches

by Shohreh
11 Oct 2021 03:35
Forum: DOS Batch Forum
Topic: Batch files only opens some files
Replies: 2
Views: 1492

Batch files only opens some files

Hello, I'm using the following list of commands to launch an application and open documents in the same instance, ie. the application is only launched once: REM open.docs.cmd start " " "C:\Program Files\SumatraPDF\SumatraPDF.exe" -reuse-instance "C:\Doc1.pdf" start " " "C:\Program Files\SumatraPDF\S...
by Shohreh
25 Aug 2020 07:55
Forum: DOS Batch Forum
Topic: Loop and append different string to each file?
Replies: 2
Views: 1823

Re: Loop and append different string to each file?

Simple enough :-) Still, would it be possible to use a second loop, since I won't know the names of the input files? I only used 1.txt 2.txt as examples. @echo off if "%~1"=="" GOTO PARAM setlocal enableextensions enabledelayedexpansion set items[0]="Some text" set items[1]="Some other text" set ite...
by Shohreh
25 Aug 2020 05:47
Forum: DOS Batch Forum
Topic: Loop and append different string to each file?
Replies: 2
Views: 1823

Loop and append different string to each file?

Hello, I'd like your input on how to solve this problem. I need to write a loop to 1) read all TXT files in a directory, and 2) insert a different string in each file. Pseudo-code: for %%f in (*.TXT) DO ( ECHO Handling %%f SELECT CASE CASE 1.TXT: echo "some text" >> %%f CASE 2.TXT: echo "some other ...
by Shohreh
11 Aug 2020 05:27
Forum: DOS Batch Forum
Topic: [SOLVED] How to get filename from URL and set it to variable?
Replies: 3
Views: 2251

[SOLVED] How to get filename from URL and set it to variable?

Hello, In a batch file, I need to rip the filename from a URL, and set it to variable. This doesn't work ("| was unexpected at this time."): REM Usage: mybatch.bat http://www.acme.com/myfile.html → extract "myfile.html" REM OK echo %1 | sed "s/.*\///" for /f %%i in ('echo %1 | sed "s/.*\///"') do se...
by Shohreh
07 Jun 2020 04:38
Forum: DOS Batch Forum
Topic: Redirect output to file without using > sign?
Replies: 12
Views: 5452

Re: Redirect output to file without using > sign?

The problem is that an input file may contain tens of thousands of track points, ie. latitude + longtidude tuples.

Maybe I should just forget about cmd batch files for this task, and require installing a full scripting language like Perl or Python.
by Shohreh
07 Jun 2020 04:12
Forum: DOS Batch Forum
Topic: Redirect output to file without using > sign?
Replies: 12
Views: 5452

Re: Redirect output to file without using > sign?

Can method #2 be modified somehow to include a call to grep in the middle, so that I can fetch track points from GPX files, insert them, and then append the end of the structure? @Echo OFF (For /F "Skip=2 Tokens=2 Delims=<>" %%A in (%~F0) Do Echo/^<%%A^>)>Output.xml Goto :EOF :<?xml version="1.0" en...
by Shohreh
07 Jun 2020 03:42
Forum: DOS Batch Forum
Topic: Redirect output to file without using > sign?
Replies: 12
Views: 5452

Re: Redirect output to file without using > sign?

It almost works: The first line ("xm version") requires question marks, but for some reason, the line is missing in the output file. Is it due to the question mark? @ECHO OFF if "%~1"=="" GOTO PARAM (For %%A in ( "<?xml version="1.0" encoding="UTF-8"?>" "<gpx>" "<trk>" "<trkseg>" ) Do Echo/%%~A)>out...
by Shohreh
07 Jun 2020 02:36
Forum: DOS Batch Forum
Topic: Redirect output to file without using > sign?
Replies: 12
Views: 5452

Re: Redirect output to file without using > sign?

Thanks, but it doesn't work on my Windows 7 computer: C:\>test2.bat >test2.xml The syntax of the command is incorrect. REM test2.bat @ECHO OFF ECHO <?xml version="1.0" encoding="UTF-8"?> ECHO <gpx> ECHO <trk> ECHO <trkseg> ECHO <trkpt lat="46.361004" lon="-1.180605"> ECHO </trkpt> ECHO </trkseg> ECH...
by Shohreh
06 Jun 2020 07:56
Forum: DOS Batch Forum
Topic: Redirect output to file without using > sign?
Replies: 12
Views: 5452

Redirect output to file without using > sign?

Hello, I'd like to use a batch file to write an XML file, but without having to rely on the usual > sign because then, every sign must be escaped: @ECHO OFF ECHO ^<?xml version="1.0" encoding="UTF-8"?^> > test.gpx ECHO ^<gpx^> >> test.gpx ECHO ^</gpx^> >> test.gpx Can Windows be told to simply outpu...
by Shohreh
27 May 2020 12:12
Forum: DOS Batch Forum
Topic: [SOLVED] SET adds space to variable?
Replies: 2
Views: 2040

Re: SET adds space to variable?

Thank you.
by Shohreh
27 May 2020 09:51
Forum: DOS Batch Forum
Topic: [SOLVED] SET adds space to variable?
Replies: 2
Views: 2040

[SOLVED] SET adds space to variable?

Hello, In a FOR loop, I need to create a couple of variables so I can make use of them later. For some reason, the following adds a space between the left side of the filename and its extension: REM c:\test.bat input.txt FOR %%f IN ("%1") DO SET left=%%~nf & SET ext=%%~xf ECHO %left%%ext% REM Displa...
by Shohreh
30 Apr 2020 08:36
Forum: DOS Batch Forum
Topic: Can SET be filled by a command?
Replies: 7
Views: 4901

Re: Can SET be filled by a command?

Thanks, it worked. But it displays 1) the fully qualified filenames (I don't need the path) and 2) it starts by displaying "!LIST! "%__DIR"". The following gets rid of the path: for %%x in (%__dir__%*) do set LIST=!LIST! "%%x" The following doesn't work, although I need to filter files: for %%x in (...
by Shohreh
29 Apr 2020 15:01
Forum: DOS Batch Forum
Topic: Can SET be filled by a command?
Replies: 7
Views: 4901

Re: Can SET be filled by a command?

Actually, in the same vein, I also need to call a command that expects a list of files at the end: myapp.exe file1.png file2.png etc. I tried the following, but it's not obviously full of data I don't need. FOR /F "delims=" %%a IN ('dir *.png') DO set "name=%%a" & echo %name% What's a good way to bu...