Computing.Net > Forums > Programming > Help with For /r loop

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Help with For /r loop

Reply to Message Icon

Name: GEM
Date: June 3, 2009 at 11:54:50 Pacific
OS: Windows XP SP3
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: June 3, 2009 at 23:17:48 Pacific
Reply:

tell us what exactly are you wanting to do.


0

Response Number 2
Name: GEM
Date: June 4, 2009 at 08:57:08 Pacific
Reply:

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?


0

Response Number 3
Name: Razor2.3
Date: June 4, 2009 at 13:04:58 Pacific
Reply:

So something like this?

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


0

Response Number 4
Name: GEM
Date: June 4, 2009 at 13:52:12 Pacific
Reply:

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.


0

Response Number 5
Name: GEM
Date: June 10, 2009 at 09:28:33 Pacific
Reply:

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
right

Thanks anyway!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Read last line from newes... excel formula



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help with For /r loop

Help with batch file (FOR /R) www.computing.net/answers/programming/help-with-batch-file-for-r-/14521.html

Help with a C Program / Newbie www.computing.net/answers/programming/help-with-a-c-program-newbie/8071.html

Help with a piece of code!! www.computing.net/answers/programming/help-with-a-piece-of-code/6023.html