Solved

Script to collect path and filename

Posted on 2011-09-29
6
358 Views
Last Modified: 2012-05-12
I need a script to be able to search a source folder for all *.pdf and then collect the finding in a TXT table.

The code below is NOT a valid code but merely an example of what I am looking for.

the table should populate like this...
DATAFILE.TXT ======================================

"FilePathName","FileName"
"\\X.X.40.119\data$\folder1","FileFound1.PDF"
"\\X.X.40.119\data$\folder1","FileFound2.PDF"
"\\X.X.40.119\data$\folder2","FileFound3.PDF"
"\\X.X.40.119\data$\folder2","FileFound4.PDF"
"\\X.X.40.119\data$\folder3","FileFound5.PDF"
"\\X.X.40.119\data$\folder3","FileFound6.PDF"

 
strSourceFolder = "\\X.X.41.40.119\erchart$"
strSourceFileSearch ="*.PDF"
strTargetDataFolder = "\\X.X.40.119\data$"
strTargetDataFilename = "MyTable.txt"

If Right(strSourceFolder, 1) <> "\" Then strSourceFolder = strSourceFolder & "\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set objSource = fso.GetFolder(strSourceFolder)
For Each oFile In objSource.Files
    Wscript.Echo "FilePathName"&", "&"FileName" to strTargetDataFilename
    Wscript.Echo objFSO.GetParentFolderName(objFile) to strTargetDataFilename
    Wscript.Echo objFSO.GetFileName(objFile) to strTargetDataFilename
Next

Open in new window

0
Comment
Question by:epicazo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
ReneGe earned 500 total points
ID: 36818838
Here you go!


@ECHO OFF
FOR /R ""\\X.X.40.119\data$" %%A IN (*.pdf) DO (
	ECHO "%%~dpA","%%~nxA"
	ECHO "%%~dpA","%%~nxA">>"output.csv"
)
PAUSE

Open in new window

0
 

Author Comment

by:epicazo
ID: 36818868
I saved it as BAT file and i get a syntax of command is incorrect
0
 

Author Closing Comment

by:epicazo
ID: 36818879
AWESOME.....   I noticed the FOR /R ""\\....  so I fixed it and works like a charm
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:ReneGe
ID: 36818884
You'r welcome :)
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36818912
And to reassemble the file names from the csv file...

I did not need to put " arround the file name. I put it in case you wanted to have a space in it.

Also because it's a file name, not a variable, I had to add usebackq.

Cheers,
Rene
@ECHO OFF
FOR /F "usebackq tokens=1,2 delims=," %%A IN ("output.csv") DO ECHO "%%~A%%~B"
PAUSE

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36818945
I guess I'm to tired to give explanations. Please do not consider my statment: "Also because it's a file name, not a variable, I had to add usebackq."

However, I did put usebackq because I put " arround the file name...

Cheers
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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