Home » Community » Newbie corner » [SOLVED] WIN32 API "MoveFile" and LineEdit Ctrl issue  
	
		
		
			   [SOLVED] WIN32 API "MoveFile" and LineEdit Ctrl issue [message #37856] | 
			Mon, 19 November 2012 06:32   | 
		 
		
			
				
				
				
					
						  
						navi
						 Messages: 107 Registered: February 2012  Location: Sydney, Australia
						
					 | 
					Experienced Member  | 
					 | 
		 
		 
	 | 
 
	
		Objective: Trying to batch rename files. 
 
Problem: WIN32 API "MoveFile" fails to rename files if the file names are fetched from LineEdit Ctrl. 
 
My guess is it has got something to do with hidden end of line char or CHARSET Unicode Ascii conversion issue. But I did not yet find a way to fix the problem. It is essential that I fetch the file name from the LineEdit Ctrl. Where the LineEdit Ctrl has multiple lines and each line is a file name. 
 
I have coded a sample program to replicate the problem. Attached are the codes and screen-shots. 
 
Thanks, 
Navi 
 
Reference: 
MoveFile function (Windows) [MSDN] 
System Error Codes (0-499) (Windows) [MSDN] 
 
 
#include <CtrlLib/CtrlLib.h>
#include <CtrlCore/CtrlCore.h>
using namespace Upp;
GUI_APP_MAIN
{
	TopWindow w;
	LineEdit e,f; 
	Vector<String> v1, v2; // Vectors for Storing File Names
	String s;      // String for temporary use
	bool r=false;  // r to keep the "MoveFile" API Return
	int err_no=0;  // err_no to keep "GetLastError" API Return
	
	// GUI SETUP CODE
	e.SetRect(10,10,680,100);
	f.SetRect(10,120,680,220);
	w.SetRect(0,0,700,350);
	
	w<<e<<f;
	// ADDING SOME DUMMY BUT VALID FILE NAMES THAT DO EXIST
	v1.Add("E:\\TEMP\\1.txt");
	v1.Add("E:\\TEMP\\2.txt");
	v1.Add("E:\\TEMP\\3.txt");
	
	// CATENATING VECTOR 'v1' INOT TEMP STRING 's' TO LOAD ALL FILE NAMEs INTO LINEEDIT
	for(int i=0; i<v1.GetCount(); i++){
		 s<<v1[i]<<"\n";
	}
	
	e.Set(s);
	
	
	// FETCHING THE FILE NAME BACK FROM THE LINEEDIT AND SPLITTING THEM INTO SEPERATE STRING
	s.Clear();
	
	s=e.Get();
	
	v2=Split(s, "\n", true);
	
	// TEST-1: RENAMEING FILES USING v1 FILE NAME TO v1 FILE NAME (Ya Same Names. for tests only!)
	s.Clear();
	s<<"DEBUG INFO: TEST-1:\n";
	
	for(int i=0; i<v1.GetCount(); i++){
		
		r=MoveFile(v1[i],v1[i]);
		
		(!r)? err_no=GetLastError() : err_no=0;	
		
		s<<"RENAME "
		 <<v1[i]<<" => "<<v1[i]
		 <<" [Done="<<r<<"] [Error="
		 <<err_no<<"]\n";		
	}
	
	// TEST-2: RENAMEING FILES USING v1 FILE NAME TO v2 FILE NAME (Ya Same Names. but from LineEdit Ctrl)
	s<<"\nDEBUG INFO: TEST-2:\n";
	
	for(int i=0; i<v1.GetCount(); i++){
		
		r=MoveFile(v1[i],v2[i]);
		
		(!r)? err_no=GetLastError() : err_no=0;	
		
		s<<"RENAME "
		 <<v1[i]<<" => "<<v2[i]
		 <<" [Done="<<r<<"] [Error="
		 <<err_no<<"]\n";		
	}	
	
	s<<"\n***Error Code 123(0x7B) = ERROR_INVALID_NAME\n";
	
	// PRINTING THE RESULTS
	f.Set(s);
	
	// Executing the Window
	w.Run();
}
 
		
	- 
	
 
	Attachment: main.cpp
	 
	(Size: 1.79KB, Downloaded 364 times)
 
 
		
		[Updated on: Mon, 19 November 2012 13:51] Report message to a moderator  
 |  
	| 
		
	 | 
 
 
 |  
  
 
	
	  | 
	  | 
	
		[SOLVED] WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  navi on Mon, 19 November 2012 06:32  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  navi on Mon, 19 November 2012 06:34  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  navi on Mon, 19 November 2012 06:36  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		 By: unknown user on Mon, 19 November 2012 08:23 
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  navi on Mon, 19 November 2012 08:44  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  koldo on Mon, 19 November 2012 08:59  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  navi on Mon, 19 November 2012 09:54  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  koldo on Mon, 19 November 2012 10:17  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  deep on Mon, 19 November 2012 11:44  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  koldo on Mon, 19 November 2012 12:44  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  deep on Mon, 19 November 2012 13:12  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  koldo on Mon, 19 November 2012 13:25  
	 | 
 
	  | 
	 | 
	
		Re: WIN32 API "MoveFile" and LineEdit Ctrl issue
		By:  navi on Mon, 19 November 2012 13:50  
	 | 
  
Goto Forum:
 
 Current Time: Tue Nov 04 07:18:14 CET 2025 
 Total time taken to generate the page: 0.05110 seconds 
 |