Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please have an eye out this question: <a href="https://stackoverflow.com/questions/2999640/iterating-through-folders-and-files-in-batch-file"><code>Iterating through folders and files in batch file?</code></a>.</p> <p>I think this should help you.</p> <p>Please let me know if you need further assistance.</p> <p><strong>EDIT #1</strong></p> <p>The joker character in DOS command line is <code>*</code>. Then, while searching a directory for certain files, you may consider your regular expression, that is, your <code>XXX_</code>, and complete it with <code>*</code>, this shall return only the files for which you're looking for.</p> <p>This means that instead of <code>*.zip</code> pattern in one of the <code>FOR</code> loops given the linked question, your first <code>FOR</code> loop should contain your directory name, then take this variable concatenated with the <code>*</code> character to obtain only the files you're looking for.</p> <p>For example, consider trying the following:</p> <pre><code>dir /s XXX_*.* </code></pre> <p>This should return only the files you're interested in, given the right folder name.</p> <p><strong>EDIT #2</strong></p> <p>Thanks for having precised your concern.</p> <p>Here is a code sample that, I do hope so, should help. Now I know you say you have the looping correct, so that perhaps only piece of this code might be needed.</p> <pre><code>@echo off setlocal enableextensions enabledelayedexpansion for /F "delims==" %%d in ('dir /ogne /ad /b /s .') do ( for /F "delims==" %%f in ('dir /b "%%d\%%~nd_*.*"') do ( echo %%d\%%f ) ) endlocal </code></pre> <p>This works and lists the files contained in subfolders from the current (<code>.</code>) folder.</p> <p>I have tested it from the following folder:</p> <blockquote> <p>C:\Docume~1\marw1\MyDocu~1\MyMusi~1</p> </blockquote> <p>Where a 'XXX' folder is contained. This 'XXX' folder contains the following files:</p> <blockquote> <ol> <li>Copy of XXX_blah.bmp;</li> <li>XXX_blah.bmp;</li> <li>XXX_1234.ppt;</li> <li>XXX_textfile.txt.</li> </ol> </blockquote> <p>From this structure, the output is:</p> <blockquote> <p>C:\Docume~1\marw1\MyDocu~1\MyMusi~1\XXX\XXX_blah.bmp C:\Docume~1\marw1\MyDocu~1\MyMusi~1\XXX\XXX_1234.ppt C:\Docume~1\marw1\MyDocu~1\MyMusi~1\XXX\XXX_textfile.txt</p> </blockquote> <p>I then suspect that putting a <code>del</code> instruction instead of an <code>echo</code> command shall do the trick. This means that to isolate the foldername itself from its path, you need to use the <code>~n</code> instruction with your folder variable name like <code>%%~nd</code>, where your iterating folder variable name is <code>%%d</code>.</p> <p>Furthermore, you could even use a parameterized batch file in the process, instead of hardcoding it, that is, if your <code>'set YourFolder =...'</code> is part of your production code. This could look like:</p> <pre><code>@echo off setlocal... set root = %1 set root = %root:~1% set root = %root:~0,-1% ... endlocal </code></pre> <p>Instead of having <code>'.'</code> as pictured in my first <code>FOR</code> loop, your would replace it with <code>"%root%"</code> in order to consider your command line parameter instead of a hardcoded filepath.</p> <p>I do help this helps, sincerely!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload