Solved

List file names in Excel

Posted on 2004-04-13
6
255 Views
Last Modified: 2010-04-13
I have a folder that stores images (jgs, tif, etc.) of forms that have been scanned. Each form is related to ONE of our customers, so we have named each image file as the CustomerID.

For example I have some files named:

34568.jpg
146.tif
267897.jpg
7654.tif
679839.tif
...

I need to create an excel file (or text file) with a list of all the IDs of the file names that have been stored. So, for the above I need an excel file that has entries:

34568
146
267897
7654
679839

Is there any way of doing this? Thanks.
0
Comment
Question by:naqayya
  • 3
  • 2
6 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 10814472
Assuming that there are no duplicates (1234.jpg and 1234.tif), and those files are in a single directory, simply enter
for %a in (*.*) do @echo %~na >>"S:\ome\Directory\id.txt"
which will create the file "id.txt" (delete the file if it exists before issuing in a command).
That can of course be put into a batch file as well:

@echo off
set OutFile=S:\ome\Directory\id.txt
if exist "%OutFile%" del "%OutFile%"
for %%a in (*.*) do echo %%~na >>"%OutFile%"

For additional goodies, you need to provide more information...
0
 

Author Comment

by:naqayya
ID: 10814674
Thanks oBdA!

I am a bit of a novice here: do I enter this command from a command prompt on the PC and do I have to be in the directory that has the files?

Thanks.
0
 

Author Comment

by:naqayya
ID: 10814766
How do I go to that directory in the command prompt? I need to get files from:
E:\GADs\0 - 50,000

(note the spaces and comma in the directory name)

Thanks!
0
[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

 
LVL 16

Expert Comment

by:JamesDS
ID: 10814840
naqayya

If this is just a one off then you could just run the following from the command line (in the right directory!)

dir /b > output.txt

The file output.txt will contain your filenames which can be imported into Excel.
You can strip off the externsion in Excel by adding a formula into the next column over from your list that goes:
=MID(A1,1,LEN(A1)-4)

Where A1 is the first cell of your list.
Copy the formula down and use the new column as your start data

Cheers

JamesDS
0
 
LVL 83

Accepted Solution

by:
oBdA earned 200 total points
ID: 10814871
To run it in the command prompt, simply enter
E:
cd "\gads\0 - 50,000"
for %a in (*.*) do @echo %~na >>"S:\ome\Directory\id.txt"

or, directly in one single command:
for %a in ("E:\gads\0 - 50,000\*.*") do @echo %~na >>"S:\ome\Directory\id.txt"

Or put it all in a batch file:

====8<----[GetIDs.cmd]----
@echo off
setlocal
set OutFile=S:\ome\Directory\id.txt
set RootDir=E:\GADs\0 - 50,000
if exist "%OutFile%" del "%OutFile%"
for %%a in ("%RootDir%\*.*") do echo %%~na >>"%OutFile%"
====8<----[GetIDs.cmd]----
0
 

Author Comment

by:naqayya
ID: 10821881
Thanks all
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now