Computing.Net > Forums > Programming > Need to get filename & size

Need to get filename & size

Reply to Message Icon

Original Message
Name: Mike (by mmcconaghy)
Date: October 18, 2007 at 12:49:57 Pacific
Subject: Need to get filename & size
OS: WinXP & Linux
CPU/Ram: unk
Model/Manufacturer: unk
Comment:

Not sure this is the correct area for this question but....

I have several hundred files, jpg & tiff
I need to get only the filename and filesize
and put them into a spreadsheet.

Any and all help appreciated.

Mike


Report Offensive Message For Removal


Response Number 1
Name: tonysathre
Date: October 18, 2007 at 14:33:54 Pacific
Reply: (edit)

@echo off
echo File Size File Name > spreadsheet.txt
echo ==================== >> spreadsheet.txt
echo. >> spreadsheet.txt
for /f "tokens=*" %%i in ('dir /b *.jpg') do (
for /f "tokens=1,2" %%j in ("%%~zni") do (
echo %%j %k >> spreadsheet.txt
)
)
for /f "tokens=*" %%i in ('dir /b *.tiff') do (
for /f "tokens=1,2" %%j in ("%%~zni") do (
echo %%j %%k >> spreadsheet.txt
)
)

For better output formatting insert 12 spaces between %%j and %%k.
"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 2
Name: Mike (by mmcconaghy)
Date: October 18, 2007 at 15:03:42 Pacific
Reply: (edit)

Thanks for the quick reply.

I gave it try and the first time thru it gave the filesize but not the filename.

Looking over the script, I changed
echo %%j %k >> spreadsheet.txt
to read
echo %%j %i >> spreadsheet.txt

and I got what I needed.

Thanks again. It's been awhile since
I did any scripting.

Mike



Report Offensive Follow Up For Removal

Response Number 3
Name: Mike (by mmcconaghy)
Date: October 19, 2007 at 18:16:38 Pacific
Reply: (edit)

If I could ask one more question on this.

I worked out most of the script except:
for /f "tokens=1,2" %%j in ("%%~zni")

How does this get the filesize?
What does ("%%~zni") do/mean?

Thanks again.
Mike


Report Offensive Follow Up For Removal

Response Number 4
Name: tonysathre
Date: October 20, 2007 at 17:31:46 Pacific
Reply: (edit)

In addition, substitution of FOR variable references has been enhanced
You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
environment variable for %I and expands to the
drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line

In the above examples %I and PATH can be replaced by other valid
values. The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.

"Computer security." — Oxymoron


Report Offensive Follow Up For Removal

Response Number 5
Name: Mike (by mmcconaghy)
Date: October 21, 2007 at 11:40:02 Pacific
Reply: (edit)

WOW,
Thnaks, that explains a lot of stuff I was wondering about.

I really appreciate the help.

Mike



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Need to get filename & size

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge