Solved

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

Posted on 2013-01-02
7
284 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

810 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