Script to collect path and filename

Posted on 2011-09-29
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 ======================================


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

Open in new window

Question by:epicazo
  • 4
  • 2
LVL 10

Accepted Solution

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

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

Open in new window


Author Comment

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

Author Closing Comment

ID: 36818879
AWESOME.....   I noticed the FOR /R ""\\....  so I fixed it and works like a charm
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

LVL 10

Expert Comment

ID: 36818884
You'r welcome :)
LVL 10

Expert Comment

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.

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

Open in new window

LVL 10

Expert Comment

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...


Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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 …
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 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