Replacing backslash with slash
Posted: 15 Feb 2009 21:13
awhile back I received some help here with a script the wrote the contents of a directory/subdirectories in their relative path. Here's the code for that;
It works properly, however I ran into a snag implementing it. Turns out I can't use backslashes (\) but forward slashes (/) will work just fine. I'm not sure how to go about doing this with the script above, I thought about having an external batch file execute after "data.xml" is written and having it go through and replace the backslashes, but seems like there must be a easier/better way to do it.
Code: Select all
@ECHO off
del data.xml
SETLOCAL ENABLEDELAYEDEXPANSION
for /F "tokens=*" %%c in ('dir *.jpg /a-d /ogn /b /s') do (
set abspath=%%~fc
call set "relpath=%%abspath:%cd%\=%%"
rem echo abs=!abspath! rel=!relpath!
echo ^<img^>!relpath!^<^/img^> >> data.xml
)
( ENDLOCAL & REM RETURN VALUES
It works properly, however I ran into a snag implementing it. Turns out I can't use backslashes (\) but forward slashes (/) will work just fine. I'm not sure how to go about doing this with the script above, I thought about having an external batch file execute after "data.xml" is written and having it go through and replace the backslashes, but seems like there must be a easier/better way to do it.