I need to be able to
- Search a directory and its subdirectories for specific files with an extension .ac There is only one of these per directory.
- I then need to be able to copy some files to the directory with the *.ac in it. When the files are being copied, they need to have the same name as the *.ac file without the extension. So if the *.ac file was foobar.ac I need to be able to copy foobarMS.cvw to the directory. It can copy just the one file but rename it to fit the directory.
- Once it is done copying the file, have it save that path in a text file
- This will loop until it has gone through all the subdirectories
When I run the script again, it would be nice to have it cross reference the list of already done directories so it doesn’t have to copy to them again. Or if it’s faster, disregard cross-referencing the list and just have the copy command not overwrite.
I have gotten so far but putting it together is causing me grief.
I am able to list the directories of the *.ac files by:
for /d /r %%a in (*) do @if exist %%a\*.ac (echo %%a)
This is what I have so far:
@echo off
cls
for /D /R %%a in (*) do @if exist "%%a\*.ac" (
if not exist "%%a\%%~Nacb.cvw" (
copy .\jzitfix.cvw "%%a\%%~Nacb.cvw">nul
)
if not exist "%%a\%%~Naia.cvw" (
copy .\jzitfix.cvw "%%a\%%~Naia.cvw">nul
)
if not exist "%%a\%%~Najzcd.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzcd.cvw">nul
)
if not exist "%%a\%%~Najzcpl.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzcpl.cvw">nul
)
if not exist "%%a\%%~Najzlnr.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzlnr.cvw">nul
)
if not exist "%%a\%%~Najzms.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzms.cvw">nul
)
if not exist "%%a\%%~Najzmt.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzmt.cvw">nul
)
if not exist "%%a\%%~Najzmu.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzmu.cvw">nul
)
if not exist "%%a\%%~Najzmv.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzmv.cvw">nul
)
if not exist "%%a\%%~Najzmw.cvw" (
copy .\jzitfix.cvw "%%a\%%~Najzmw.cvw">nul
)
if not exist "%%a\%%~Nalt.cvw" (
copy .\jzitfix.cvw "%%a\%%~Nalt.cvw">nul
)
if not exist "%%a\%%~Nams.cvw" (
copy .\jzitfix.cvw "%%a\%%~Nams.cvw">nul
)
if not exist "%%a\%%~Namt.cvw" (
copy .\jzitfix.cvw "%%a\%%~Namt.cvw">nul
)
if not exist "%%a\%%~Namu.cvw" (
copy .\jzitfix.cvw "%%a\%%~Namu.cvw">nul
)
if not exist "%%a\%%~Namv.cvw" (
copy .\jzitfix.cvw "%%a\%%~Namv.cvw">nul
)
if not exist "%%a\%%~Namw.cvw" (
copy .\jzitfix.cvw "%%a\%%~Namw.cvw">nul
)
if not exist "%%a\fixed" (
copy .\jzitfix.cvw "%%a\fixed">nul
echo FIXED: %%~Na
echo %%~Na >> fixed.txt
)
)
ADDENDUM
Excuse me; perhaps I misunderstood some point. Based on your first description, my code do the following:
FOR each path\file with .ac extension (for example, “foobar.ac”):
copy a file that have the same name plus “MS” and .cvw extension (for example “foobarMS.cvw”) to the same path AND save that path in a text file, but only if that file doesn’t exist.
I deduced the last part (“only if that file doesn’t exist”) from your requirements: “When I run the script again, it would be nice to… doesn’t have to copy to them again. Or… just have the copy command not overwrite”).
Your explanation clearly said: “When the files are being copied, they need to have the same name as the *.ac file without the extension…”, and “Once it is done copying the file, have it save that path in a text file”. So, I don’t understand where the multiple names of your second example come from.
Perhaps your first description is unclear and should be:
If this is the case, then I don’t know when “save that path in a text file”: When each file is copied (repeating the same path for each missing file)? Or just once for each path? Or only if at least one of the files was copied?
The Batch file below is a modified version in accordance with previous description:
If this still is not what you want, then please explain with more detail and examples what you want!