get list of sub-folders/files W/O foll path

Microsoft Windows xp professional w/ sp2
July 10, 2010 at 15:32:24
Specs: Windows XP, lol
Ok so here is my script so far:

@echo off
set publiclink=http://(host)/u/(unique ID)/
if exist "public\index.html" del "public\index.html"
for /r "public" %%g in (*) do echo ^<a 
href^="%publiclink%%%~nxg"^>%%~nxg^</a^> >> 

the purpose, as you can see, is to get a list of files within a directory, which the script also resides in.
It also gathers a list of files within sub-folders as well.
It outputs that text to an HTML file in a link:

(a href=http://internal_file_host/file_name.ext)file_name.ext(/a)(br)(br)

Here is the problem:
It outputs ONLY file names.
This would be an easy fix, except that I don't need the FULL PATH. I only want the sub-path. In other words, if the script is in C:\folder, and the file is in C:\folder\public, I want the script to return something like "public\filename.ext"

Does that make sense?

I don't care how we have to do it, even if it has to be customized for each user (it's in a sub-directory of the user folder, usually desktop or documents) - but I need to figure out a way to do that.

If you folks can help me out a bit, I would be eternally grateful! :)

EDIT: For added clarity, I wanted to specify that this is for a program which takes a folder and hosts the files in it, on a server. The structure of the URL to that file is:

www.(our server).com/(folder containing file, if any)/(file name).(extension)

EDIT2: One method I thought of was to grab the full path of all files in that folder and its sub-folders, then strip out the previx (c:\users\%username%\etc.) but that would be difficult, especially since we'd have to ask the user to change the script to fit their installation path.

maybe we can do something like....

look for the path the script is being run from, save that to var1, then get the full path of all files in their sub-folders and remove any instances of "var1" from that text?

I wouldn't know how to do this; still learning! :P

See More: get list of sub-folders/files W/O foll path

Report •

July 10, 2010 at 17:01:28
funny you should ask that... i just put one out there a couple days ago:
it was like this:
@echo off & setlocal enabledelayedexpansion
for /r "public" %%g in (*) do (
set xx=%%~pg
for /f "tokens=*" %%b in ("!xx!") do set parent=%%~nxb
echo fullpath: !xx!, parent: !parent!, file: %%~nxa

Report •

July 10, 2010 at 17:18:57
Thanks very much for the tip; Would you mind helping me
understand it so that I can customize it for my own situation?
The FOR loop in batch is poorly documented and I've got little
info on it. :P
I don't know if this is exactly what I'm trying to do - I imagine it would be easier in VB, but I'm not good with vb yet :P

Report •

July 10, 2010 at 19:03:27
i'll try, not much to the snippet...
for /f %%a in ('dir /b /s *.xxx')
is the replacement/equivalent of your "for /r" loop. all it does is
gather the filenames from the cur.wk.dir on down. Consider it as a "bolt-up swap": i used %%a, you used %%g, is only diff.
Inside that loop, the inner "for"-loop (we can ignore the "grandfather" clause, that was just a demo) is only used to convert "user" var. !xx! to "system" variable %%b in order to gain access to the path extraction tools not available to user-variables. So in that regard, it's essentially not a loop, but just a method to capture and manipulate the string !xx!.
If you run the snippet, you can see what it does and from there adapt it to your needs if acceptable.
(i fixed a goof , made a to g, and added echo off etc. in resp# 1.)

Report •

Related Solutions

July 10, 2010 at 19:16:10
Thank you very much, but I don't think that this is quite what I'm
looking for. It doesn't seem to work in my situation. What I need
is a way to output just "file1.ext" or "\dir1\file1.ext". I've got a few
methods of doing /similar/ actions, but nothing that really gets
me exactly there.

Report •

July 10, 2010 at 20:23:52
Someone helped me figure it out exactly! :D

@echo off && setlocal ENABLEEXTENSIONS

for /d %%j in (public*) do (
set publicroot=%%~dpnj

set publiclink=http://(host)/u/(unique ID)/

if exist "public\index.html" del "public\index.html"
for /r "Public" %%g in (*) do (
set spew=^%%g^</a^>
set spew=!spew:%publicroot%\=!
echo !spew:\=/! >> public\index.html

Report •

Ask Question