Solved

Script to collect path and filename

Posted on 2011-09-29
6
357 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
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.

 
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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

791 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