Avoiding DOS space related "path not found errors"

Well I have a lot of scripts that require dragging and dropping files in order to define Source files etc.

However more often then not it is the case that the path to said file contains NUMEROUS spaces.

I know one way to evade this problem is to encase the path in Quotes like this:

"C:/Path/to file/"

Sadly it seems that this won't solve all problems related to this.

I recall that it was possible to have DOS recognize Space's in paths and work without a hitch by calling a specific command prior to the path.

Since I could not find said command again:

Any help appreciated.

In this situation I would suggest to use short path.

You can get short path by running:

dir /x

Or in CLI or batch file you can get them by running:

for /d %I in (*) do @echo %~sI

The second code will just ouput:

sI cannot be processed here

Works for me!

C:\>for /d %I in (*) do @echo %~sI
C:\APACHE~1.27
C:\BD630A~1
C:\Dell
C:\DOCUME~2
C:\DOCUME~1
C:\Drivers
C:\local
C:\oracle
C:\PROGRA~1
C:\Temp
C:\WINDOWS

C:\>VER

Microsoft Windows XP [Version 5.1.2600]

well... it seems that

for /d %%I IN (*) do @echo %%~sI

works...

STILL a problem remains:

this code cannot be used when the path is like this:

C:\Program Files\TEST\test it out.png

because the last part is a file...

What do I have to get that to work ?

C:\>for %A in ("C:\PROGRA~1\TEST\*.*") do @echo %~sA
C:\PROGRA~1\TEST\TESTIT~1.PNG

Oh well, at this point I think it is the best to post the script so you will understand why it is quite hard to implement:

SET /P SOURCE=Drag and drop the image to be altered (SOURCE):
SET /P toreplace=Drag and drop the pattern to be searched for (MATCH):
SET /P replacingpattern=Drag and drop the pattern that will replace the searched pattern (REPLACE):
set SRC="%SOURCE%"
set SUB="%toreplace%"
set REP="%replacingpattern%"

the variable paths SOURCE, toreplace and replacingpattern are what I need to work with spaces.

You help was quite helpfull so far ! Thanks.

OK, in that case short paths are going to be a problem for search & replace.

I guess you should convert the format from long to short and vice versa to achieve this.

Look at for help and see if there are any modifiers that can be used for this requirement:

for /?

Other than that I am not sure how this can be done!