Changing to a dynamically named directory

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Changing to a dynamically named directory

Post by gchichester » Wed Nov 04, 2015 11:23 am

I'm trying to access files in a directory that gets a new name daily during a backup job.
Example of folder name E:\ServerName\Backup 2015-10-28 223032
I tried using wildcards with ChangeDirectory> like you can in a command prompt E:\>cd Serv*\Backu*,
Line 59: Error: Directory E:\>cd ServerName\Backu* Does Not Exist.

Anyone know of a creative way to drill down into this directory?
Thank you in advance for all your help
Gil

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Changing to a dynamically named directory

Post by armsys » Wed Nov 04, 2015 2:39 pm

gchichester wrote:I'm trying to access files in a directory that gets a new name daily during a backup job....
The following code helps you enumerate folders with names Backup yyyy-mm-dd hhmmss:
All found folder names are stored in: FolderName_1, FolderName_2, FolderName_3,...,etc.
Finally, the folder names are sorted in ascending order so that the last one is the latest backup folder.

Code: Select all

// Purpose: Search folders with names Backup yyyy-mm-dd hhmmss
// Folders only
Let>GFL_TYPE=1
Let>GFL_ATTRIBUTES=16
GetFileList>c:\Temp\Backup*.*,Folders
Separate>Folders,;,FolderName
ArraySort>FolderName
Let>LastFolder=FolderName_%FolderName_Count%
ChangeDirectory>LastFolder
MDL># of Folders Found: %FolderName_count%

gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Re: Changing to a dynamically named directory

Post by gchichester » Wed Nov 04, 2015 5:34 pm

Thanks for the code, Worked as expected until I hit the following directory structure
E:\Servers\ExchangeMailDBBkup\10282015_0500\WindowsImageBackup\servername\Backup 2015-10-28 213019
Not sure how to get by the third directory name, and yes it changes daily

Thanks
Gil
Thank you in advance for all your help
Gil

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Changing to a dynamically named directory

Post by armsys » Wed Nov 04, 2015 10:45 pm

gchichester wrote:Thanks for the code, Worked as expected until I hit the following directory structure
E:\Servers\ExchangeMailDBBkup\10282015_0500\WindowsImageBackup\servername\Backup 2015-10-28 213019
Not sure how to get by the third directory name, and yes it changes daily
Gil
Please try the following code:

Code: Select all

// Purpose: Search folders with names Backup yyyy-mm-dd hhmmss
// Your Target Folder Name:  E:\Servers\ExchangeMailDBBkup\10282015_0500\WindowsImageBackup\servername\Backup 2015-10-28 213019
// My test Folder hierarchy: C:\Temp\ExchangeMailDBBkup\...

Day>Day
Month>Month
Year>Year
// Date for Folder Level 3 (FL3Date)
Let>FL3Date=%Month%%Day%%Year%

// Date for Folder Level 6 (FL6Date)
Let>FL6Date=%Year%-%Month%-%Day%

// Folders only
Let>k=1
Let>FL3=
Let>GFL_TYPE=1
Let>GFL_ATTRIBUTES=16

Repeat>k
  Let>Srh=Srh%k%
  If>k=1
    Let>Srh=c:\Temp\ExchangeMailDBBkup\%FL3Date%_*.*
  Else
    Let>Srh=%FL3%\WindowsImageBackup\servername\Backup %FL6Date%*.*
  Endif
  GetFileList>Srh,Folders
  Separate>Folders,;,FolderName
  ArraySort>FolderName
  Let>CurFolder=FL
  ConCat>CurFolder,{if(%k%=1,"3","6")}
  Let>%CurFolder%=FolderName_%FolderName_Count%
  Add>k,1
Until>k>2
// Jump to Folder Level 6
ChangeDirectory>FL6

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts