I have a programming question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • pswauger
    Forum Member
    • Apr 2005
    • 16

    I have a programming question

    I am new to this application, and I have a question maybe someone here could point me in the right direction. I am trying to write code that searches the c:\ for a file called user.tkn. Once it finds this file it copies the folder above it and the user.tkn file to backup folder. Anyone have any ideas on how i can accomplish this? I can find the file, but the second part is where i am getting stuck.
    Thanks,
    Pete
  • ianhull
    Forum Member
    • Jul 2004
    • 314

    #2
    Is the file in a folder in c:\\ ?
    To move the file as a backup use

    File.Copy("C:\\MyDir\\user.tkn*.*", "C:\\Backup\\user.tkn", true, true, false, true, nil);


    Hope this helps

    Comment

    • pswauger
      Forum Member
      • Apr 2005
      • 16

      #3
      ...

      Yes the file (user.tkn) is always somewhere on c:\\. Now what I need to know is how to parse the file path that would be found when running the result = File.Find("C:\\", "user.tkn", false, true, nil, nil);

      Basically if the user.tkn file is located at C:\mydirectory\anotherdirectory\USERNAME\user.tkn
      I want to copy the USERNAME\user.tkn to C:\backup. Hopefully I explained what I am trying to do a little better that time.
      Thanks for the help again.

      Comment

      • TJ_Tigger
        Indigo Rose Customer
        • Sep 2002
        • 3159

        #4
        Try this, it uses Worms function to copy a folder

        Code:
        function CopyFolder(sSource, sDestination)
        	local m_sFolder;
        	local m_FoundFolder;
        	local error;
        	
        	--Find all the folders and sub-Folders
        	--results are stored in the table m_tblFolders
        	m_tblFolders = Folder.Find(sSource, "*", true, nil);
        	
        	--if our destination folder does not have the 
        	--backslash as the last character, add it
        	if String.Right(sDestination, 1) ~= "\\" then
        		sDestination = sDestination .. "\\";
        	end
        	
        	--m_tblFolders will be nil if there are no folders 
        	if m_tblFolders ~= nil then
        		--enumerate through the found folders
        		for n, m_FoundFolder in m_tblFolders do
        			--replace the source's path with the destination's path
        			m_sFolder = String.Replace(m_FoundFolder, sSource, sDestination, false);
        			--create the folder
        			Folder.Create(m_sFolder);
        			error = Application.GetLastError();
        			if (error ~= 0) then
            			--set n to value to exit FOR loop
            			n = Table.Count(m_tblFolders)
        			end
        		end
        	else
        		error = 0
        	end
        
        	--if no errors occurred, copy the files
        	if (error == 0) then
        		--show the status dialog
        		StatusDlg.Show(MB_ICONNONE, false);
        		--copy all files from the source folder, with recurse.
        		File.Copy(sSource .. "\\*.*", sDestination, true, true, false, true, nil);
        		--hide the status dialog
        		StatusDlg.Hide();
        		error = Application.GetLastError();
        	end
        
        	--clean up
        	m_tblFolders = nil;
        	return error;
        end
        
        tbFiles = File.Find("c:\\", "user.tkn", true, false, nil, nil);
        if tbFiles then
        	for i,v in tbFiles do
        		--split the path into parts to identify the folder
        		tbSplit = String.SplitPath(tbFiles[i]);
        		--replace the single \'s with \\
        		tbSplit.Folder = String.Replace(tbSplit.Folder, "\\", "\\\\", false);
        		--build the parent folder for the found file
        		strSource = tbSplit.Drive..tbSplit.Folder;
        		--build the destination folder
        		strDest = "c:\\Backup"..tbSplit.Folder;
        		--use Worms Copy Folder function to copy the source to destination
        		CopyFolder(strSource, strDest);
        	end
        end
        Tigg
        TJ-Tigger
        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
        "Draco dormiens nunquam titillandus."
        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

        Comment

        Working...
        X