C#使用System.IO,System.Data和&amp ;;基于文件和传输文件的邮政编码值创建目录。 CSVReader

现有应用程序:我有一个C#应用程序,它运行搜索并获取匹配的潜在客户文件并将它们引入特定目录。 添加功能:让系统检查文件的邮政编码是否存在子目录,如果不存在则创建它,然后我希望将文件转移到相应的目录中。 问题:现在,没有文件正在传输,也没有创建任何子目录。什么都没发生。这是语法问题还是我称之为错误? 请帮忙! 这是我添加的内容:
            string targetzipdir = m_sc.get_TargetPath() + "\" + ZIP;
            // If the zip code subdirectory doesn't exist, create it.

            if (!Directory.Exists(targetzipdir))
            {
                 Directory.CreateDirectory(targetzipdir);
            } 

         private void TransferFile(string sourceDir, string filename, string ZIP)     
         { 
            string targetFileAndPath = m_sc.get_TargetPath() + "\" + ZIP + "\" + fullFileName;
这里有更多的SearchProcess.cs文件中的代码,用于更大的图片(有些东西没有了):
    public void Run()
    {
        m_sc = (SearchCriteria)m_form.Invoke(m_form.m_DelegateGetSearchCriteria);
        // Display parameters
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Corp: " + m_sc.get_Corp() });
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on OrderNumber: " + m_sc.get_OrderNumber() });
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Campaign: " + m_sc.get_Campaign() });
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on City: " + m_sc.get_City() });
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on State: " + m_sc.get_State() });
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Zip: " + m_sc.get_Zip() });
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Source Path: " + m_sc.get_SourcePath() });
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] { "Search on Target Path: " + m_sc.get_TargetPath() });

        DirSearch(m_sc.get_SourcePath());

        // Make asynchronous call to main form
        // to inform it that thread finished
        m_form.Invoke(m_form.m_DelegateThreadFinished, null);
    }

            for (int colNum = 0; colNum < expectedTypes.Count; colNum++)
            {
            if (m_sc.get_SearchOR().Equals(true))
                // Check for the Zip match
                if (m_sc.get_Zip() != "" && ZIP.Contains(m_sc.get_Zip()) == true)
                {
                    found = true;

                    string targetzipdir = m_sc.get_TargetPath() + "\" + ZIP;
                    // If the zip code subdirectory doesn't exist, create it.

                    if (!Directory.Exists(targetzipdir))
                    {
                        Directory.CreateDirectory(targetzipdir);
                    } 

                }     // ending if (m_sc.get_SearchOR().Equals(true))
            }         //ending for loop  

    private void TransferFile(string sourceDir, string filename, string ZIP)
    {
        string fullFileName = filename + ZIP + ".pdf";
        string fullFileNameAndPath = sourceDir + "\" + fullFileName;

        //copy matching source file into the specified subdirectory based on zip
        string targetFileAndPath = m_sc.get_TargetPath() + "\" + ZIP + "\" + fullFileName;
        // Copy the file if the source file exists
        if (File.Exists(fullFileNameAndPath))
        {
            m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"COPYING FROM: " + fullFileNameAndPath});
            m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"TO: " + targetFileAndPath});
            // Do the copy, overrite the target file if it exists
            File.Copy(fullFileNameAndPath, targetFileAndPath, true);
        }
        else
        {
            m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"Source file does not exist: " + fullFileNameAndPath});
        }
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] {""});
    }
谢谢你的期待!任何想法将不胜感激! :)     
已邀请:
我发现了问题!我有在错误的地方创建目录的代码。它位于邮政编码匹配的If语句下,只有在邮政编码匹配且邮政编码是搜索中的可选字段时才会执行。我移动了TransferFile方法下的所有代码,它工作正常。此外,数据的源目录必须指向C: Documents and Settings bmccarthy Desktop sourcedir,并且文件必须采用特殊格式,位于该目录的子目录下 C: Documents and Settings bmccarthy Desktop sourcedir AMLDailyHotLeads20101001 这是重写的代码:
            // Copy the file if ANY of the search criteria have been met
            if (found)
            {

                m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"FOUND: Order_No: " + Order_No +
                                                                        " barcode: " + barcode +
                                                                        " MailerCode: " + MailerCode +
                                                                        " AgentID: " + AgentID +
                                                                        " City: " + City +
                                                                        " State: " + State +
                                                                        " ZIP: " + ZIP});
                //passes values to TransferFile 
                TransferFile(directory, barcode, AgentID, ZIP);
            }
        } // end for that finds each matching record 

    }

    // find and copy the file to the target directory string ZIP
    private void TransferFile(string sourceDir, string filename, string AgentID, string ZIP)
    {
        string fullFileName = filename + ".pdf";
        string fullFileNameAndPath = sourceDir + "\" + fullFileName;
        string targetFileAndPath;

            // adds the given lead's agentid and zip code to the targetpath string 
            string targetzipdir = m_sc.get_TargetPath() + "\" + AgentID + "\" + ZIP;

            // If the given lead's zip code subdirectory doesn't exist, create it.
            if (!Directory.Exists(targetzipdir))
            {
                Directory.CreateDirectory(targetzipdir);
            }

            targetFileAndPath = m_sc.get_TargetPath() + "\" + AgentID + "\" + ZIP + "\" + fullFileName;

        // Copy the file if the source file exists
        if (File.Exists(fullFileNameAndPath))
        {
            m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"COPYING FROM: " + fullFileNameAndPath});
            m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"TO: " + targetFileAndPath});

            // Copy the file and over-write the target file if it exists
            File.Copy(fullFileNameAndPath, targetFileAndPath, true);
        }
        else
        {
            m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"Source file does not exist: " + fullFileNameAndPath});
        }
        m_form.Invoke(m_form.m_DelegateAddString, new Object[] {""});
    }
    

要回复问题请先登录注册