Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Is there a way to include multiple sets (both positive and negative) in one variable inside of a for /r loop? Here's the command I'm using:
for /r %%i in (*.shp) do copy "%%i" "%%~pni_wgs.shp" /-Y
But, I also want to check for something like this:
for /r %%i in (*.shp) and not in (*_wgs.shp) do copy "%%i" "%%~pni_wgs.shp" /-Y

I wrote a batch file to make a copy of a file and add "_wgs" to the filename (not the extension). However, I don't know whether the folders (which could number 300 or so and contain 29 or more subfolders each) if there are any existing files already with a "filename_wgs.shp" name. I have to assume that since I haven't run my batch on the folder yet, that the file was created manually and I don't want to overwrite it.
I would like the command that creates the copy to take into account all *.shp files in the loop, but exclude anything that already contains "_wgs.shp" in the filename.
I tried using the /-Y, but it requires a manual reply and I don't want to use /Y because, as I said earlier, I don't want to overwrite the file. Does that help?

So something like this?
for /r %%i in (*.shp) do IF NOT EXIST "%%~PNi_wgs.shp" copy "%%i" "%%~pni_wgs.shp"

Yes, exactly ... however, this command still duplicates the existing "%%~PNi_wgs.shp" copy so I end up with "%%~PNi_wgs_wgs.shp".
I got that result with another attempt, but different set of commands:
did not work:
if not exist *_wgs.shp for /r %%i in (*.shp) do copy "%%i" "%%~pni_wgs.shp"I understand you can include multiple file sets in the in section, such as:
in (*.shp *.doc *.txt)
However, I have not been successful in performing a negative set.

In case anyone is interested, here's the solution. Text in bold font is what you change.
-----Code-----
For /F "delims=" %%I In ('Dir /A-D /B /S *.dbf^|Findstr /I /V /G:excludelist.txt^|Findstr /E /I /L /V "_wgs.dbf"') Do If Not Exist "%%~pnI_wgs.dbf" Copy "%%I" "%%~pnI_wgs.dbf"
---------------Contents of excludelist.txt file:
left
rightThanks anyway!

![]() |
Read last line from newes...
|
excel formula
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |