Solved

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

Posted on 2013-01-02
7
282 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 28

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 28

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 28

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
shadow copies 7 16
Computer software inventory 5 36
Home folder in File server 8 39
Password Expiry 9 19
Learn about cloud computing and its benefits for small business owners.
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
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 to another domain controller. Log onto the new domain controller with a user account t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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