Solved

Nightly process produces file name that needs to be moved and renamed.  Is this possible?

Posted on 2013-01-02
7
285 Views
Last Modified: 2013-01-11
I have scheduled an export to run daily.  The directory to where the export is scheduled to be run is hard coded and cannot be changed.  Is it possible to schedule another process to pick up the export and dump it into another folder where I have another program that needs to call it?

The export is running to:  \\server1\GVP96\Downloads with a file name of:  BER1004_86204_EESETUP_SCHED_20121227_173754 (where 20121227 is the YYYYMMDD and changes each day and where 173754 is a number assigned by the software and changes each day) and is a text document.

The program that needs to pick it up looks in another directory on another server.
0
Comment
Question by:bergquistcompany
  • 3
  • 3
7 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 38738831
you can write a powershell script to do this:

Here is an idea.
$FileList = Get-ChildItem \\server1\GVP96\Downloads -recurse | Where-Object {$_.PSIsContainer -eq $True}
ForEach ($FileObj in $FileList) {
if ($fileobj.Name -like ("*20121227*")
      {

$fullpath = $FileObj.FullName
$sourcefolder = "\\server1\GVP96\Downloads\"
$destFolder = "path you want to copy files to"
$copypath = ($fullpath -replace [regex]::Escape($SourceFolder), '')
$destpath = $DestFolder + $copypath

write-host "processing $fullpath" -fore green
Copy-Item $fullpath $destpath

}
0
 
LVL 9

Expert Comment

by:Brian
ID: 38741528
Just schedule a simple one line batch file.

xcopy \\server1\GVP96\Downloads\BER1004_86204_EESETUP_SCHED_*.txt \\server1\destination

This will move all files with that name to the destination folder. Save that one line as a batch file and schedule it to run after the export will finish.
0
 

Author Comment

by:bergquistcompany
ID: 38745340
@washburnma this will be perfect, but one question is can the file BER1004... be renamed to import.txt on the destination side as that is the file name the software looks for to pick up?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 29

Expert Comment

by:becraig
ID: 38748928
My script above would provide that flexibility with one extra line but it seems you don't want to go that route.
0
 

Author Comment

by:bergquistcompany
ID: 38751893
@becraig

I'd love to try it, can you help me with the added line for taking the .txt file and renaming to user.csv?  Then can I use schedule task to run this script daily?
0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 38752721
Here you go:

param ([string] $source, [string] $dest, [string] $pattern);
if ((($source -eq "") -or ($dest -eq "") -or ($pattern -eq "")))
    {
    write-host "
    Incorrect Syntax:
    `t Usage: copy-files.ps1 -source \\server\filepath -dest c:\destinationfolder -pattern 210124 (Pattern foldername should match)
    " -fore Red
    }
else 
{
$FileList = Get-ChildItem $source -recurse | Where-Object {$_.PSIsContainer -eq $True}
ForEach ($FileObj in $FileList) {
if ($fileobj.Name -like "$pattern")
    {
$fullpath = $FileObj.FullName
$filepath = (gci $fullpath -recurse) 
foreach ($file in $filepath) 
        {
         $fullfilepath = $File.FullName
         $copypath1 = ($fullfilepath -replace [regex]::Escape($Source), '')
         $copypath = [regex]::Replace($copypath1,".txt",".csv");
         $destpath = $Dest + $copypath
         if($destpath -like "*.csv"){Copy-Item $fullfilepath $destpath} 
         
        }
    } 
                                }                                
}
                           

Open in new window

               



save as copy-files.ps1
to run as scheduled task
powershell.exe copy-files.ps1 -source \\sourcefolder -dest \\destination-folder -pattern date pattern to check for (you can add a wildcard - e.g. 2012*)

Usage: The script does a recursive check for each folder beneath the folder you specify as source and copies the full path as defined copying only the files matching *.csv  


If you have anything else you want the script to do let me know.
0
 

Author Closing Comment

by:bergquistcompany
ID: 38768527
awesome
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
This article outlines the process to identify and resolve account lockout in an Active Directory environment.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

821 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