Solved

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

Posted on 2013-01-02
7
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Uncontrolled local administrators groups within any organization pose a huge security risk. Because these groups are locally managed it becomes difficult to audit and maintain them.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

617 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