Link to home
Create AccountLog in
Avatar of bergquistcompany
bergquistcompany

asked on

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

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.
Avatar of becraig
becraig
Flag of United States of America image

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

}
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.
Avatar of bergquistcompany
bergquistcompany

ASKER

@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?
My script above would provide that flexibility with one extra line but it seems you don't want to go that route.
@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?
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
awesome