Computing.Net > Forums > Windows XP > Batch File

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.

Batch File

Reply to Message Icon

Name: Juan Pablo
Date: August 24, 2009 at 07:42:11 Pacific
OS: Windows XP
CPU/Ram: 1 GB
Product: Microsoft Windows xp inside out
Subcategory: Software Problems
Tags: batch
Comment:

Hi,

I am trying to create a batch file that searches for all lnk files that contain the word "rica" in its path.
It works fine. The problem is that if the file namehas spaces, it doesn´t work.
Example: if the file "hi.lnk" has the word "rica" it works fine and it is deleted, but if the file name is "hi 2.lnk" it does not worl and takes "hi" as a folder.
Can you help me with that please?
Thanks!



Sponsored Link
Ads by Google

Response Number 1
Name: Juan Pablo
Date: August 24, 2009 at 07:45:24 Pacific
Reply:

This is the code I have

@echo off
for /f "delims= " %%a in ('findstr /M /I /S "rica *.lnk') do (
::echo deleting %%a
del %%a
echo Shortcut deleted
pause
)

:fin

Thanks!


0

Response Number 2
Name: kptech
Date: August 24, 2009 at 08:54:29 Pacific
Reply:

Try this instead:

for /f "delims=," %%a in ('findstr,/M,/I,/S,"rica,*.lnk') do (

You defined a space as the delimiter so the spaces in the filenames were also processed as delimiters instead of part of the filenames.

If we use a comma as the delimiter, when a space is encountered in the filename it's just ignored and included as part of the path\filename...

-- kptech


0

Response Number 3
Name: Juan Pablo
Date: August 24, 2009 at 09:59:58 Pacific
Reply:

Thanks for the response.
I tried it and the same happens :S

Is that the way you say?

@echo off
for /f "delims=, " %%a in ('findstr, /M, /I, /S, "rica", *.lnk') do (
::echo Borrando %%a
del %%a
echo Shortcut borrado
pause
)
:fin

Sorry to disturb you. Do you have any idea why the same could be happening?

Maybe I explained it wrong. What I want to look for is the word "rica" in its target path, and the problem occurs when the file name has a space.

Thanks in advance kptech!



0

Response Number 4
Name: Juan Pablo
Date: August 24, 2009 at 12:15:38 Pacific
Reply:

I could fix it!

@echo off

for /f "delims=," %%a in ('findstr,/M,/I,/S,"rico",*.lnk') do (

::echo Borrando %%a
del "%%a"
echo Shortcut borrado
pause
)

:fin

I would like to search upwards. For example, if a shortcut containing "rico" is located in C:/ when I run it in desktop shpuld also be deleted. Is that posible?
Thanks!




0

Response Number 5
Name: kptech
Date: August 31, 2009 at 18:39:07 Pacific
Reply:

Sounds like you just want to search the entire drive. To do that, just start your search at the root of the drive like this:

@echo off
c:
cd \
for /f "delims.......

-- kptech


0

Related Posts

See More



Response Number 6
Name: Juan Pablo
Date: September 1, 2009 at 06:16:09 Pacific
Reply:

Thanks kptech!

What I want to do now is to display a message if it founds nothing. I tried with ERRORLEVEL but it always returns a 0.

How can I do this?

Thanks in advance!


0

Response Number 7
Name: kptech
Date: September 3, 2009 at 12:49:29 Pacific
Reply:

This is one way...

@echo off
c:
cd\
set filesfound=0
for /f "delims=," %%a in ('findstr,/M,/I,/S,"rico",*.lnk') do (

::echo Borrando %%a
set filesfound=1&del "%%a"
echo Shortcut borrado
pause
)

if [%filesfound%]==[0] echo No files were found to delete!
:fin


1

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch File

Batch file www.computing.net/answers/windows-xp/batch-file/180885.html

Auto folder Batch file www.computing.net/answers/windows-xp/auto-folder-batch-file/145055.html

simple batch file www.computing.net/answers/windows-xp/simple-batch-file/149160.html