1,105,416 Community Members

windows batch script to get files with same name, but different extension

Member Avatar
CPT
Light Poster
41 posts since Aug 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

First, to explain what I want to do: I have a folder structure like this:

BSDS300\images\test\ -which contains JPEG files, and some other files(only .jpg files are of interest)
BSDS300\human\color\ -which contains many folders, in which I have .seg files with the same name as the .jpg file

Example:
BSDS300\images\test\3096.jpg
BSDS300\human\color\1110\3096.seg
BSDS300\human\color\1109\3096.seg

What I want is to generate a text file in the first location with the same name as the .jpg file, which will contain the absolute paths of every location that contains a .seg file(with the same name)

what I've tryed so far, is something in the command prompt window:

for %f in (*.jpg) do echo %~ff

but this only writes the .jpg absolute path preceded by the word echo

Member Avatar
RikTelner
Junior Poster
141 posts since Jan 2013
Reputation Points: 4 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 
setlocal

if not exist "BSDS300\human" md "BSDS300\human"
if not exist "BSDS300\human\color" md "BSDS300\human\color"

(for %%d in (BSDS300\images) do (
    if exist "%%d" (
            pushd "%%d"
                for %%f in (*.jpg) do (
                    move "%%f" "BSDS300\human\color\%%f"
                )
        popd
    )
))
set /p pause=Finished. Press "enter" to exit.
You
Post:
Start New Discussion
View similar articles that have also been tagged: