Computer Hope

Microsoft => Microsoft DOS => Topic started by: crushnik on September 30, 2021, 09:00:01 AM

Title: Combining multiple filepaths into one line
Post by: crushnik on September 30, 2021, 09:00:01 AM
I would like to streamline some of the functions I do constantly. One of which is copying the filepaths of multiple files and making one line of text for example:

If I select
file1.txt
file2.txt
file3.txt
and right-click while holding the SHIFT key I can "copy as path."

I paste the group of paths into Notepad++ which gives me three different lines. My example is simplified; I have to deal with far more files in my workflow.

From there, I hit END, DELETE, SPACE after each file. It's good mental exercise I suppose, but it's tedious given how many times I have to do this in a day and surely there is a command script I could use where I can automate the process.

I have reverse-engineered some scripts some friends have used in the ballpark of what I'm trying to do, and surely it would be something along the lines of
cmd /v:on
set x=F:\path
for %f in (x) do (whatever)
but maybe it's something entirely different.

Any help would be greatly appreciated!
Title: Re: Combining multiple filepaths into one line
Post by: crushnik on September 30, 2021, 09:54:03 AM
Actually I discovered "macros" after posting. That streamlined one step of the process.

Would there be a way to copy and paste the last line?

For example I can now use a macro to turn
"file1.txt"
"file2.txt"
"file3.txt"
into
"file1.txt" "file2.txt" "file3.txt"

but I'd like it to be
"file1.txt" "file2.txt" "file3.txt" "file3.txt"
Title: Re: Combining multiple filepaths into one line
Post by: dphamnj on September 30, 2021, 08:57:44 PM
Is it okay to use javascript ?  Please save the code below to a file with extension html, eg, combine_lines.html, then open it with browser.  See attached image for the screen in browser.

Code: [Select]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Combine lines</title>
</head>
<body>
    <p/>Input:
    <p/><textarea id="inputId" style="width:450px;height:150px;">
line1
line2
line3
    </textarea>
    <p/><button type="button" onclick="combine()">combine</button>
    <p/>Output:
    <p/><textarea readonly id="outputId" style="width:450px;height:150px;"></textarea>
    <p/>
    <script>
        function combine() {
            var indata = document.getElementById('inputId');
            var lines = indata.value.split('\n');
            var outdata = "";
            var line = "";
            for (var i=0; i < lines.length; i++) {
                lines[i].trim();
                if (lines[i].length > 0) {
                    line = lines[i];
                    outdata += line + " ";
                }
            }
            if (line.length > 0)
                outdata += line;
            document.getElementById('outputId').innerHTML = outdata;
        }
    </script>
</body>
</html>
Title: Re: Combining multiple filepaths into one line
Post by: crushnik on October 01, 2021, 07:12:50 AM
I tried HTML and couldn't get it to work. But I am able to get part of what I want using a Notepad++ macro.
Title: Re: Combining multiple filepaths into one line
Post by: crushnik on October 01, 2021, 07:43:39 AM
Here is what I'm wanting to do:
1) use list geo to produce file1.gtf from file1.tif
2) use gdal_translate to produce file1_a.tif from file1.tif
3) use nconvert to modify file1_a.tif and not file1.tif
4) use geotifcp to put metadata from file1.gtf back in modified image (file1_a.tif) and overwrite file1.tif

Code: [Select]
cmd /v:on
set tif=F:\path
for %f in ("%tif%\*_V.tif") do (
set filename=%~nf
listgeo -d "%f" > "%tif%\!filename!.gtf"
gdal_translate -b 1 -b 2 -b 3 -of GTiff -co INTERLEAVE=PIXEL "%f" "%tif%\!filename!_a.tif"
geotifcp -g "file1.gtf" "file1_a.tif" "file1.tif"
"F:\path\to\nconvert.exe" -overwrite -replace "file1_a.tif"
geotifcp -g "file1.gtf" "file1_a.tif" "file1.tif"
)

Is there a good way of doing this? I can do step one, but I don't know the commands to use one particular file and not the other.
Title: Re: Combining multiple filepaths into one line
Post by: DaveLembke on October 01, 2021, 09:14:17 PM
Curious why the meta data needs to be passed back into it?
Title: Re: Combining multiple filepaths into one line
Post by: crushnik on October 02, 2021, 07:22:58 AM
Removing metadata so it isn't stripped when I edit the imagery.

Through trial-and-error I figured out how to have the script run automatically through the step where nconvert edits the *_a.tif file, but the step where I re-insert the metadata has me stumped since I don't know how to run a command where I target the *.tif file but not the *_a.tif file. Probably very simple, but I haven't learned that one yet.
Title: Re: Combining multiple filepaths into one line
Post by: dphamnj on October 02, 2021, 07:29:12 AM
Hi,

My DOS programming is rusty so it takes me sometimes to test.  You can try to save the code below to a .bat file and run it in DOS.

Since I don't have listgeo, gdal_translate, etc programs installed so I assume your commands are good.

Here is some notes:
o it seems variable cannot be set inside the for loop
o the for loop variable %f needs to specify as %%f in a .bat file
o For parsing DOS variables, run "hep for" to see available notes and examples.

Good luck.

Code: [Select]
@echo off
setlocal
set tif=F:\path
for %%f in (%tif%\*_V.tif) do (
  listgeo -d %%f > %tif%\%%~nf.gtf
  gdal_translate -b 1 -b 2 -b 3 -of GTiff -co INTERLEAVE=PIXEL %%f %tif%\%%~nf_a.tif
  geotifcp -g %tif%\%%~nf.gtf %tif%\%%~nf_a.tif %%f
  "F:\path\to\nconvert.exe" -overwrite -replace %tif%\%%~nf_a.tif
  geotifcp -g %tif%\%%~nf.gtf %tif%\%%~nf_a.tif %%f
)
endlocal