Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Files\Folder

Files\Folder

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewVC
    wrote on last edited by
    #1

    Hi All How can i identify root is file or folder?I have a String Path="C:\\Tets\\tr.txt" and String Path1="C:\\abc.txt".How can i identify Path root is Folder and Path1 root is File.Plz help me

    H _ _ N D 5 Replies Last reply
    0
    • N NewVC

      Hi All How can i identify root is file or folder?I have a String Path="C:\\Tets\\tr.txt" and String Path1="C:\\abc.txt".How can i identify Path root is Folder and Path1 root is File.Plz help me

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Im not sure its your answer or no do you need to CString::Mid or CString::Right?

      Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

      N 1 Reply Last reply
      0
      • N NewVC

        Hi All How can i identify root is file or folder?I have a String Path="C:\\Tets\\tr.txt" and String Path1="C:\\abc.txt".How can i identify Path root is Folder and Path1 root is File.Plz help me

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        See WIN32_FIND_DATA and use FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_NORMAL etc

        You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

        N 1 Reply Last reply
        0
        • H Hamid Taebi

          Im not sure its your answer or no do you need to CString::Mid or CString::Right?

          Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

          N Offline
          N Offline
          NewVC
          wrote on last edited by
          #4

          i use find ,mid and Right.But i need to check only root is Folder or Not?

          1 Reply Last reply
          0
          • _ _AnsHUMAN_

            See WIN32_FIND_DATA and use FILE_ATTRIBUTE_DIRECTORY, FILE_ATTRIBUTE_NORMAL etc

            You need to google first, if you have "It's urgent please" mentioned in your question. ;-)_AnShUmAn_

            N Offline
            N Offline
            NewVC
            wrote on last edited by
            #5

            As you reply i use this code.

            CFileFind finder;

            BOOL bWorking = finder.FindFile(\_T(Path));
            
            while (bWorking)
            {
                bWorking = finder.FindNextFile();
            
                if (finder.MatchesMask(FILE\_ATTRIBUTE\_HIDDEN | 
                                       FILE\_ATTRIBUTE\_SYSTEM))
                {
                    \_tprintf\_s(\_T("%s\\n"), (LPCTSTR) finder.GetFileName());
                }
            }
            

            Path="C:\\Test\\abc.txt" or Path="C:\\tets.txt".In the both case currsor enter in while loop.But I need to check String have only file or Files/Folder Both. Plz help me

            1 Reply Last reply
            0
            • N NewVC

              Hi All How can i identify root is file or folder?I have a String Path="C:\\Tets\\tr.txt" and String Path1="C:\\abc.txt".How can i identify Path root is Folder and Path1 root is File.Plz help me

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              If the path is always the absolute path, why not check if \\ occurs more that once.

              «_Superman_» I love work. It gives me something to do between weekends.

              N 1 Reply Last reply
              0
              • _ _Superman_

                If the path is always the absolute path, why not check if \\ occurs more that once.

                «_Superman_» I love work. It gives me something to do between weekends.

                N Offline
                N Offline
                NewVC
                wrote on last edited by
                #7

                can you give me some dummy code?

                CFileOperation fo;

                	 CString string1;
                	finalString=strFileName;
                			
                	char \* szMyString = (char \*)(LPCTSTR)finalString;	
                	
                
                	CString string = \_T(szMyString);
                
                			int nPosp = strFileName1.Find( \_T("\\\\Windows"));
                
                	if( nPosp >= 0)
                	{    
                		CString DirPath21 = strFileName1.Mid( 0, nPosp +1 );
                		
                		return;
                		
                	}
                		int nPosp1 = strFileName1.Find( \_T("\\\\Backup"));
                
                	if( nPosp1 >= 0)
                	{    
                		CString DirPath211 = strFileName1.Mid( 0, nPosp1 +1 );
                		
                		return;
                		
                	}
                	int nPosp2 = strFileName1.Find( \_T("\\\\Users"));
                
                	if( nPosp2 >= 0)
                	{    
                		CString DirPath212 = strFileName1.Mid( 0, nPosp2 +1 );
                		
                		return;
                		
                	}
                
                
                	CString DirPath121;
                	int nPos = string.Find( \_T('\\\\') ,3);
                	if( nPos >= 3)
                	{    
                		DirPath121 = string.Mid( 0, nPos  );
                		
                		LPCSTR pF1=DirPath121;
                	
                	LPCSTR pT1="c:\\\\Backup";
                	
                	
                	if (!fo.Copy(pF1,pT1));
                	}
                	else
                	{
                	 string1=string;
                	string1 +='\\0';
                	
                	if(string1=="")
                	{
                		
                		//break;
                	}
                	int nLen = string1.GetLength();
                
                	LPCSTR lpszBuf = string1.GetBuffer(nLen);
                
                	string1.ReleaseBuffer();
                
                
                	LPCSTR pF=lpszBuf;
                	
                	LPCSTR pT="c:\\\\Backup";
                	
                	
                	if (!fo.Copy(pF,pT));
                	}
                

                modified on Wednesday, March 18, 2009 8:39 AM

                _ 1 Reply Last reply
                0
                • N NewVC

                  Hi All How can i identify root is file or folder?I have a String Path="C:\\Tets\\tr.txt" and String Path1="C:\\abc.txt".How can i identify Path root is Folder and Path1 root is File.Plz help me

                  N Offline
                  N Offline
                  Nishad S
                  wrote on last edited by
                  #8

                  You might be searching for PathIsRoot API...

                  - ns ami -

                  1 Reply Last reply
                  0
                  • N NewVC

                    Hi All How can i identify root is file or folder?I have a String Path="C:\\Tets\\tr.txt" and String Path1="C:\\abc.txt".How can i identify Path root is Folder and Path1 root is File.Plz help me

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Have you checked out _splitpath()? The dir argument will contain "\tets\" for the former and "\" for the latter.

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    1 Reply Last reply
                    0
                    • N NewVC

                      can you give me some dummy code?

                      CFileOperation fo;

                      	 CString string1;
                      	finalString=strFileName;
                      			
                      	char \* szMyString = (char \*)(LPCTSTR)finalString;	
                      	
                      
                      	CString string = \_T(szMyString);
                      
                      			int nPosp = strFileName1.Find( \_T("\\\\Windows"));
                      
                      	if( nPosp >= 0)
                      	{    
                      		CString DirPath21 = strFileName1.Mid( 0, nPosp +1 );
                      		
                      		return;
                      		
                      	}
                      		int nPosp1 = strFileName1.Find( \_T("\\\\Backup"));
                      
                      	if( nPosp1 >= 0)
                      	{    
                      		CString DirPath211 = strFileName1.Mid( 0, nPosp1 +1 );
                      		
                      		return;
                      		
                      	}
                      	int nPosp2 = strFileName1.Find( \_T("\\\\Users"));
                      
                      	if( nPosp2 >= 0)
                      	{    
                      		CString DirPath212 = strFileName1.Mid( 0, nPosp2 +1 );
                      		
                      		return;
                      		
                      	}
                      
                      
                      	CString DirPath121;
                      	int nPos = string.Find( \_T('\\\\') ,3);
                      	if( nPos >= 3)
                      	{    
                      		DirPath121 = string.Mid( 0, nPos  );
                      		
                      		LPCSTR pF1=DirPath121;
                      	
                      	LPCSTR pT1="c:\\\\Backup";
                      	
                      	
                      	if (!fo.Copy(pF1,pT1));
                      	}
                      	else
                      	{
                      	 string1=string;
                      	string1 +='\\0';
                      	
                      	if(string1=="")
                      	{
                      		
                      		//break;
                      	}
                      	int nLen = string1.GetLength();
                      
                      	LPCSTR lpszBuf = string1.GetBuffer(nLen);
                      
                      	string1.ReleaseBuffer();
                      
                      
                      	LPCSTR pF=lpszBuf;
                      	
                      	LPCSTR pT="c:\\\\Backup";
                      	
                      	
                      	if (!fo.Copy(pF,pT));
                      	}
                      

                      modified on Wednesday, March 18, 2009 8:39 AM

                      _ Offline
                      _ Offline
                      _Superman_
                      wrote on last edited by
                      #10

                      if (strchr(string, '\\') != strrchr(string, '\\'))
                      root is folder.
                      else
                      root is file.

                      Here i'm checking if the first instance of '\\' is equal to the last instance of '\\'.

                      «_Superman_» I love work. It gives me something to do between weekends.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups