Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching for a folder with wildcards

Status
Not open for further replies.

Stefan84

Programmer
Dec 23, 2010
2
RO
Hello all,

I have a have a little problem with finding a folder...
The folder has the following name: Report_yyyymmddhhmmms
The name of the folder is based on the time it was created. what i need is to find the folder and rename it to just report.

example from c:\Report_201012231200345 to c:\Report

I wrote some code but im a beginner in vbs programming so there isnt much point in posting it.

Im trying to implement the code in VBScript in WinCC.

Please help me.
 
The question is not well posed. How do you assure there is only one directory of that "wildcard" form? (C:\Report_* or more restrictive wildcard C:\Report_??????????????, or even full-blown regular expressive form.) If there are more than one, for what reason do you want to rename to the same path name c:\Report, let alone if you can or cannot do that?
 
There is always only 1 folder of that form.

I need to send an automatic email everyday with an attachment. Unfortunally the file i need to attach is created by WinCC everyday in a folder with the structure: C:\Report_yyyymmddhhmmms

In order to do this what i had in mind is to rename the folder everyday, send the email and then delete the folder.

example:
Monday 10:00 AM the folder C:\Report_yyyymmddhhmmms was created.
Monday 10:01 AM the folder C:\Report_yyyymmddhhmmms is renamed C:\Report
Monday 10:02 AM email is sent
Monday 10:03 AM folder c:\Report is deleted

The next day has the same events.
 
If that is for sure under c:\ without the need of subdirectory recursive serach and that there is only one directory resemble the needed wildcard and of that specific form, that takes out a lot of other considerations in the script.
[tt]
[green]'givens to the need; modify to suit specific need; they can pass as arguments to sub/function construction
d=date
dir_pfx="c:\report_"
dir_target="c:\report"
'In case not specifically the date of executing this script, you need to change this.
d_sfx=year(d) & right("00" & month(d),2) & right("00" & day(d),2)
[/green]
dim dir_search, sdir, fso, cdir, odir

dir_search=dir_pfx & d_sfx
sdir=""
set fso=createobject("scripting.filesystemobject")
set cdir=fso.getfolder("c:\").subfolders
for each odir in cdir
if strcomp(left(odir.path,len(dir_search)), dir_search, 1)=0 then
sdir=odir.path
exit for
end if
next
set cdir=nothing

if sdir<>"" then
if fso.folderexists(sdir) then
fso.deletefolder sdir, true 'logic sweetener
elseif fso.fileexists(sdir) then
fso.deletefile sdir, true 'of necessity
end if
end if
fso.movefolder sdir, dir_target
set fso=nothing
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top