Solved

Script to collect path and filename

Posted on 2011-09-29
6
346 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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