Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6140587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:08:14+00:00 2026-05-23T18:08:14+00:00

I have a windows service , that takes files with metadata(FIDEF) and corresponding video

  • 0

I have a windows service , that takes files with metadata(FIDEF) and corresponding video file and , translates the XML(FIDEF) using XSLT .

I get the file directory listing for FIDEF’s and if a video file of the same name exists it translates it. That works ok , but it is on a timer to search every minute. I am trying to handle situations where the same file name enters the input directory but is already in the output directory. I just have it changing the output name to (copy) thus if another file enters i should get (copy)(copy).mov but the service won’t start with filenames of the same directory already in the output , it works once and then does not seem to pick up any new files.

Any Help would be great as I have tried a few things with no good results. I believe its the renaming methods, but I’ve put most of the code up in case its a clean up issue or something else.
(forgive some of the names just trying different things).

    private void getFileList()
    {
        //Get FILE LIST FROM Directory
        try
        {
            // Process Each String/File In Directory
            string result;
            //string filename;
             filepaths = null;
             filepaths = Directory.GetFiles(path, Filetype);

            foreach (string s in filepaths)
            {

                for (int i = 0; i < filepaths.Length; i++)
                {
                    //Result Returns Video Name
                    result = Path.GetFileNameWithoutExtension(filepaths[i]);
                    FileInfo f = new FileInfo(filepaths[i]);

                    PreformTranslation(f, outputPath + result , result);


                }
            }

        }
        catch (Exception e)
        {
            EventLog.WriteEntry("Error " + e);
        }


    }

    private void MoveVideoFiles(String Input, String Output)
    {
        File.Move(Input, Output);

    }
    private string GetUniqueName(string name)
    {


         //Original Filename
        String ValidName = name;
        //remove FIDEF from filename
        String Justname1 = Path.GetFileNameWithoutExtension(name);
        //get .mov extension 
        String Extension2 = Path.GetExtension(Justname1);
        //get filename with NO extensions
        String Justname = Path.GetFileNameWithoutExtension(Justname1);
        //get .Fidef
        String Extension = Path.GetExtension(name);
        int cnt = 0;

        //string[] FileName = Justname.Split('(');
        //string Name = FileName[0];

        while (File.Exists(ValidName)==true)
        {
            ValidName = outputPath + Justname + "(Copy)" + Extension2 + Extension;
            cnt++;

        }
        return ValidName;
    }
    private string getMovFile(string name)
    {
        String ValidName = name;
        String Ext = Path.GetExtension(name);
        String JustName = Path.GetFileNameWithoutExtension(name);

        while(File.Exists(ValidName))
        {
            ValidName = outputPath + JustName + "(Copy)" + Ext;
        }
        return ValidName;
    }



    //Preforms the translation requires XSL & FIDEF name.
    private void PreformTranslation(FileInfo FileName, String OutputFileName , String result)
    {

        string FidefName = OutputFileName + ".FIDEF";
        String CopyName;
        String copyVidName = outputPath + result;

            XslCompiledTransform myXslTransform;
            myXslTransform = new XslCompiledTransform();
            try
            {
                myXslTransform.Load(XSLname);

            }
            catch 
            {
                EventLog.WriteEntry("Error in loading XSL");
            }
            try
            {   //only process FIDEF's with corresponding Video file
                if (AllFidef == "no")
                {
                    //Check if video exists if yes,
                    if (File.Exists(path + result))
                    {
                        //Check for FIDEF File Already Existing in the Output Directory. 
                        if (File.Exists(FidefName))
                        {
                            //Get unique name
                            CopyName = GetUniqueName(FidefName);
                            copyVidName= getMovFile(copyVidName);


                            //Translate and create new FIDEF. 

                            //double checking the file is here
                            if (File.Exists(outputPath + result))
                            {
                                myXslTransform.Transform(FileName.ToString(), CopyName);
                                File.Delete(FileName.ToString());
                                MoveVideoFiles(path + result, copyVidName);

                            }
                            ////Move Video file with Corresponding Name. 

                        }


                        else
                        {  //If no duplicate file exsists in Directory just move. 
                            myXslTransform.Transform(FileName.ToString(), OutputFileName + ".FIDEF");
                            MoveVideoFiles(path + result, outputPath + result);
                        }
                    }

                    }
                else
                {
                    //Must have FIDEF extension
                    //Processes All FIDEFS and moves any video files if found. 
                    myXslTransform.Transform(FileName.ToString(), OutputFileName + ".FIDEF"); 
                    if (File.Exists(path + result))
                    {
                        MoveVideoFiles(path + result, outputPath + result);
                    }


                }
            }
            catch (Exception e)
            {
                EventLog.WriteEntry("Error Transforming " + "FILENAME = " + FileName.ToString()
                    + " OUTPUT_FILENAME = " + OutputFileName + "\r\n" +"\r\n"+  e);

            }

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:08:15+00:00Added an answer on May 23, 2026 at 6:08 pm

    There is a lot wrong with your code. getFileList has the unneeded inner for loop for starters. Get rid of it. Your foreach loop has s, which can replace filepaths[i] from your for loop. Also, don’t do outputPath + result to make file paths. Use Path.Combine(outputPath, result) instead, since Path.Combine handles directory characters for you. Also, you need to come up with a better name for getFileList, since that is not what the method does at all. Do not make your method names liars.

    I would simply get rid of MoveVideoFiles. The compiler just might too.

    GetUniqueName only works if your file name is of the form name.mov.fidef, which I’m assuming it is. You really need better variable names though, otherwise it will be a maintenance nightware later on. I would get rid of the == true in the while loop condition, but that is optional. The assignment inside the while is why your files get overwritten. You always generate the same name (something(Copy).mov.fidef), and as far as I can see, if the file exists, I think you blow the stack looping forever. You need to fix that loop to generate a new name (and don’t forget Path.Combine). Maybe something like this (note this is untested):

    int copyCount = 0;
    while (File.Exists(ValidName))
    {
        const string CopyName = "(Copy)";
        string copyString = copyCount == 0 ? CopyName : (CopyName + "(" + copyCount + ")");
        string tempName = Justname + copyString + Extension2 + Extension;
        ValidName = Path.Combine(outputPath, tempName);
        copyCount++;
    }
    

    This generates something(Copy).mov.fidef for the first copy, something(Copy)(2).mov.fidef for the second, and so on. Maybe not what you want, but you can make adjustments.

    At this point you have a lot to do. getMovFile looks as though it could use work in the same manner as GetUniqueName. You’ll figure it out. Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows Service that takes the name of a bunch of files
So clients upload Excel files to us and we have a windows service that
I have a service that sometimes calls a batch file. The batch file takes
We have taken over some .NET 1.1 Windows Service code that spawns threads to
I have a windows service that runs various system monitoring operations. However, when running
I have a windows service that runs fine, but I have to have it
I have a Windows service that runs implementations of a framework across multiple threads.
I have a windows service that has a custom configuration section. In the configSectionHandler
I have a Windows service that runs as a logged-in user (local admin). During
I have a windows service that generates logs as it does some execution. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.