Solved

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

Posted on 2013-01-02
7
283 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Most of the applications these days are on Cloud. Cloud is ubiquitous with many service providers in the market. Since it has many benefits such as cost reduction, software updates, remote access, disaster recovery and much more.
I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now