Jump to content
  • Advertisement
Sign in to follow this  
Tertsi

Windows filerenaming techniques

This topic is 5046 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I try to run this renaming test application, it gives the following errors in debug mode: 'testbase.exe': Loaded 'C:\WINNT\system32\NTDLL.DLL', Cannot find or open a required DBG file. 'testbase.exe': Loaded 'C:\WINNT\system32\KERNEL32.DLL', Cannot find or open a required DBG file I noticed that SetFileShortName() needs win XP and I'm running on win 2k, so how can I rename a file in win 2k?
int main()
{
	string foldername;
	cout << "Enter folder name." << endl;
	cin >> foldername;
	int fileindex = 0;
	string filenamestring, tempstring;

	WIN32_FIND_DATA findfiledata;
	HANDLE hFind, hFile;
	foldername += "\\*.*";
	hFind = FindFirstFile(foldername.c_str(), &findfiledata);

	if(hFind != INVALID_HANDLE_VALUE)
	{
		tempstring = findfiledata.cFileName;
		tempstring.erase(0,tempstring.find("."));
		filenamestring = '0' + tempstring;
		hFile = CreateFile(findfiledata.cFileName,
        GENERIC_ALL,
        0,
        NULL,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        NULL);
		SetFileShortName(hFile, filenamestring.c_str());

		while (FindNextFile(hFind, &findfiledata) != 0) 
		{
			++fileindex;
			tempstring = findfiledata.cFileName;
			tempstring.erase(0,tempstring.find("."));
			filenamestring = inttostring(fileindex) + tempstring;
			hFile = CreateFile(findfiledata.cFileName,
			GENERIC_ALL,
			0,
			NULL,
			OPEN_EXISTING,
			FILE_ATTRIBUTE_NORMAL,
			NULL);

			SetFileShortName(hFile, filenamestring.c_str());
		}
	}
	CloseHandle(hFile);
	FindClose(hFind);

	return 0;
}

[Edited by - Tertsi on November 25, 2004 5:02:44 PM]

Share this post


Link to post
Share on other sites
Advertisement
Try MoveFileEx or MoveFile to rename your files or directories.
It's very simple to use and is supported from win95 up.
Info on msdn is here

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!