-1

I need to perform a file moving operation from one folder to another folder on remote desktop based on the month that files has been created and modified. I need to move the files(from folder A) of previous month to folder b. This service has to run(automatically) every month at the end so that the files will be moved to folder B

http://devproconnections.com/net-framework/how-build-folder-watcher-service-c

please guide me am new to C#.

  • what is your specific question? – BugFinder Aug 23 '16 at 09:38
  • files moving from one folder to another folder via windows service @BugFinder – Fayazbasha Aug 23 '16 at 09:39
  • What have you googled on file copies? – BugFinder Aug 23 '16 at 09:41
  • no the link i mentioned is i got from google for my search. I need to move the files not copying the files @ BugFinder – Fayazbasha Aug 23 '16 at 09:43
  • 1
    So you didnt look up copying files at all – BugFinder Aug 23 '16 at 09:43
  • No i didn't actually my criteria is to cut files and paste it in another location so only i didn't looked of it @ BugFinder – Fayazbasha Aug 23 '16 at 09:45
  • It sounds like you have a lot of reading to do - you need to read on creating a service - you need to understand the differences between running it and running it as a service.. you may have to read up on credentials, scheduling, file copies, errors.. and you wont be cutting and pasting.. so, theres going to be a lot you need to sort out in your head, and plan before you do – BugFinder Aug 23 '16 at 09:59

3 Answers3

1

Just move the file, eg

System.IO.File.Move("\\pcName\c$\temp\fileA.txt", "\\pcName\c$\newDir\fileB.txt");

REF: https://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Thank you Jeremy but i need to create a windows service its just a method i dont know how to use it all – Fayazbasha Aug 23 '16 at 09:46
  • 1
    @Fayazbasha you need to read up more on programming, I could tell you how to make a Windows Service and call this method but I'd just be feeding you fish for a day and not **teaching you** how to fish for a lifetime. You need to do research before asking on here, see [ask] – Jeremy Thompson Aug 23 '16 at 09:51
  • 1
    @Fayazbasha Why do you need to create a windows service? An easier solution is to use a batch file and Windows Task Scheduler. You will be saving yourself time. Please see my answer. – tmutton Aug 23 '16 at 10:00
  • 1
    It would also make sense to run it on the machine in question rather than someone elses – BugFinder Aug 23 '16 at 10:00
0

If I understand correctly

Move all files from folder A to folder B on the last day of each month

Then what I suggest is to use a batch file command to move the files, triggered by Windows Task Scheduler at monthly intervals.

Batch command (MyBatchFile.bat):

move c:\a\* c:\b

Windows Task Scheduler:

schtasks /create /tn "FayazbashaApp" /tr c:\MyBatchFile.bat /sc monthly /mo lastday /m *
tmutton
  • 1,091
  • 7
  • 19
  • 42
  • is it possible to move the files on remote desktop am looking for automated windows service that runs on monthly basis and transfer the files to the particular location – Fayazbasha Aug 23 '16 at 09:58
  • Please elaborate further. Are the two folders on different machines? To be clear: move c:\a\* c:\b where these two folders are located on the c drive. – tmutton Aug 23 '16 at 10:02
-1

Why don't you use a simple Scheduled Task using Robocopy or even your own Console App?

A Windows Service that will only be needed once a month seems like overkill to me.

Also, I would definitely not use .NET I/O Framework for this kind of thing, it's not as atomic as one would expect, you'd be better off with Robocopy.

Pedro Luz
  • 973
  • 5
  • 14