Windows: extract filenames from folder

241 Views Asked by At

This is my first post ever here, I'll try to be straight as I can.

I'm on Windows 7. Surely DOS could execute this. Maybe an app could do this?

I would like to extract/copy all filenames with or without extension from 200+ files that are on a specific folder. Then, print/past all names in a txt file, keeping alphabetic order (mandatory).

Those files are webfonts. Each font is in several format: .woff, .svg, .eot, .ttf, etc. The main goal is to quickly write a maxi CSS file for reference with bunch css @font-face rules. Then copy/paste the rules for testing, on a production CSS file on FTP.

This is the first approach.

The best should be to progressively replace strings ( "FontName" and "fontname" in this case ):

@font-face {
    font-family: 'FontName';
    src: url('http://yoursite.com/fonts/fontname.eot');
    src: url('http://yoursite.com/fonts/fontname.eot?#iefix') format('embedded-opentype'),
        url('http://yoursite.com/fonts/fontname.woff') format('woff'),
        url('http://yoursite.com/fonts/fontname.ttf') format('truetype'),
        url('http://yoursite.com/fonts/fontname.svg#fontname') format('svg');
}
@font-face {
    font-family: 'FontName';
    src: url('http://yoursite.com/fonts/fontname.eot');
    src: url('http://yoursite.com/fonts/fontname.eot?#iefix') format('embedded-opentype'),
        url('http://yoursite.com/fonts/fontname.woff') format('woff'),
        url('http://yoursite.com/fonts/fontname.ttf') format('truetype'),
        url('http://yoursite.com/fonts/fontname.svg#fontname') format('svg');
}
@font-face {
    font-family: 'FontName';
    src: url('http://yoursite.com/fonts/fontname.eot');
    src: url('http://yoursite.com/fonts/fontname.eot?#iefix') format('embedded-opentype'),
        url('http://yoursite.com/fonts/fontname.woff') format('woff'),
        url('http://yoursite.com/fonts/fontname.ttf') format('truetype'),
        url('http://yoursite.com/fonts/fontname.svg#fontname') format('svg');
}

Etc...

I know that Coda app on Mac could help a lot on selective pasting, BTW I don't have anymore a Mac and can't find any good tools for help.

Thanks for helping.

2

There are 2 best solutions below

0
On

This code may give you a good starting point:

@echo off
setlocal EnableDelayedExpansion

set "lastFamily="
for /F "tokens=1,2 delims=." %%a in ('dir /B') do (
   if "%%a" neq "!lastFamily!" (
      if defined lastFamily (
         echo    ;
         echo }
      )
      set "lastFamily=%%a"
      echo @font-face {
      echo    font-family: '%%a';
      echo    src:
   )
   if "%%b" equ "eot"  echo        url('http://yoursite.com/fonts/%%a.eot?#iefix') format('embedded-opentype'),
   if "%%b" equ "woff" echo        url('http://yoursite.com/fonts/%%a.woff') format('woff'),
   if "%%b" equ "ttf"  echo        url('http://yoursite.com/fonts/%%a.ttf') format('truetype'),
   if "%%b" equ "svg"  echo        url('http://yoursite.com/fonts/%%a.svg#%%a') format('svg');
)
echo    ;
echo }
0
On

Like a_horse_with_no_name said, there is no "DOS" in Windows anymore.

Assuming you meant cmd.exe,

Put all file names into a file - sorted

dir /b > files.txt

Then you can do something similar to below. Warning:untested, so edit as required.

for /f "tokens=1" %a in ('type files.txt') do echo url
('http://yoursite.com/fonts/' %~nxa ') format (' %~xa ') >> outfile.txt