[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script to collect path and filename

Posted on 2011-09-29
6
Medium Priority
?
366 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

831 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