Un-removable folders: continued

Pages: 12


HELP: CREATING UNREMOVE-ABLE FOLDERS?!
IWishIKnew (221) May 10, 2012 at 8:46pm
Hello. I wrote a flash cards program that allows you to save sets of flash cards in a folder called "saved" and the subfolder which is named by the user. The problem is if the USER NAMES THE FOLDER SOMETHING THAT PRECEDES "...", that entire folder "cannot be found. You can see it in the folder viewer, and even look at the files inside it. But when you try to make any attribute changes, move it, copy it, etc., "the directory does not exist". I believe it has somthing to do with the name. I made 2 saves: 1 called "totoo", the other "totoo...". "totoo" was deleted by me, but when i tried to delete "totoo..." it couldnt find the directory address. If there is anything i can do to remove/name-change the folder, I would SOOOOOO very much appreciate it!! This is a bug i will be fixing (so this must be what happens when 'special' characters are allowed in a folder name huh?).
Disch (7763) May 10, 2012 at 9:31pm
I'm having a hard time following what you're saying. Can you clarify a bit more?

Your program can see the folder, but it can't modify it? I doubt the name of the folder has anything to do with it.
Last edited on May 10, 2012 at 9:32pm
modoran (823) May 11, 2012 at 7:46am
Get a linux live cd and delete it from there :)

Windows has some name limitations, which NTFS/FAT32 filesystems doesn't.

Or try to use UNC paths to circumvent this limitation.
Disch (7763) May 11, 2012 at 9:17am
Get a linux live cd and delete it from there :)


It's cute how Linux enthusiasts like to suggest "use Linux" as a fix for even the most trivial problems in Windows.

But then I suppose they are the type that enjoy doing lots more work than necessary in order to do simple tasks -- hence why they use Linux.
IWishIKnew (221) May 12, 2012 at 2:36pm
Disch, shutup. Modoran is trying to be helful, unlike you. Any other pesimistic resposes will be promptly reported. I'm getting sick of it. Go to some other forum for that.

By the way, i have Backtrack Linux on a flash drive. It isnt that hard to boot up on an alternate OS. So, i will try that. TY Modoran.
Last edited on May 12, 2012 at 2:37pm
firedraco (5197) May 12, 2012 at 3:57pm
Disch, shutup. Modoran is trying to be helful, unlike you. Any other pesimistic resposes will be promptly reported. I'm getting sick of it. Go to some other forum for that.


u mad?

*pessimistic response*
Last edited on May 12, 2012 at 3:58pm
Disch (7763) May 12, 2012 at 7:49pm
I was trying to be helpful in my original post. It's very unlikely that the name of a folder is preventing you from deleting it (especially since the name does not contain any unusual characters). I would need more info to determine what's really going on.

modoran was not trying to be helpful, he was being a wiseguy*. "Use a different OS" is about as useful of an answer as "buy a new computer". It was a jab Linux advocates often take when someone posts any kind of problem they're having with Windows because they like to brag about how much better Linux is than Windows. I've seen it enough to recognize it -- maybe you haven't.


That said, if you could show us some code for a small program that reproduces your trouble, I might be able to help you solve it. But I'm still a little unclear on exactly what your problem is. I can say, though, that whatever the problem is, it's very unlikely that the name of the file/folder is the problem. very very unlikely.


* with the 'Linux' comment, anyway. The UNC suggestion was a genuine response



ANOTHER EDIT: But you're right. I shouldn't have responded the way I did. It was immature.
Last edited on May 12, 2012 at 8:00pm
IWishIKnew (221) May 12, 2012 at 9:34pm
It isnt actually code. All it does is create a folder whose name is predetermined by the user when he/she names it when a prompt is shown. It's the most basic thing. Modoran is right, NFTS filesystems do have that limitation. I would find iut helpful if someone explained how i could circumnavigate this with this so called "UNC" method I've never heard of.
Disch (7763) May 12, 2012 at 10:17pm
It isnt actually code. All it does is create a folder whose name is predetermined by the user when he/she names it when a prompt is shown.


So this isn't a program you're making? The prompt is just the windows prompt? If so, then what are you putting on the cli to create this folder?


'UNC' is a naming convention you can use when working with paths in WinAPI:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

Search the page for "\\?\"
andywestken (1520)
Well, it was a program I wrote to create the un-removeable folders.

@IWishIKnew

The "\\?\" prefix that Disch mentions will allow you to remove your folder. I used the following fragment after my little experiment (see below)

1
2
3
4
5
6
7
8



#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int main() {
RemoveDirectory("\\\\?\\C:\\Tmp\\Hello...");

return 0;
}



Out of interest, how are you creating the "totoo..." folder in the first place?

When I use CreateDirectory with the path "C:\Tmp\Hello...", I just get a folder called "Hello", as Windows assumes I've given it an empty extension.

Using the "\\?\" prefix allows me to create the folder, but Explorer really hates it (I'm still using Windows XP at home, and I cannot even see inside the folder).

The safest approach would prob. be to escape your program's folder names so the file system doesn't have to deal with any problematic chars. Though you'll need to make sure you only escape the bits you want to, rather than the whole string, so Windows can still understand the folder hierarchy.

While you could invent your own scheme, I suggest you base it on the one used used to escape URLs. That is, all problematic chars are replace with % + the hex version of their ASCII or UTF-8 encoding
http://en.wikipedia.org/wiki/Url_encoding

For a subfolder called "Hello..." in C:\Tmp, that ends up as
"C:\Tmp\Hello%2e%2e%2e" in Explorer.

If you allow the user to use all prohibited chars as part of their subfolder name, then you'll need to handle at least \/:*?"<>| as well as . and % (as it's used to mark the escaped chars). So over applying it to "C:\Tmp\Hello..." would have ended up with a subfolder called "C%3a%5cTmp%5cHello%2e%2e%2e", probably created in your apps own directory, if you have sufficient access rights.

And then your program has to be able to un-escape it, too.

Andy


And you speak of actual C++ to create folders and remove them?!?! Please, can you tell me the functions and their arguments for creating, removing, and re-naming folders? PLEASE? Right now I just have my programs write a batch command to do those things (including accidentally making the un-removeable folder).

The batch command my program wrote: "md folder\subfolder1\subfolder2\"

So, essentially, it will make any name, even one with "...".
Last edited on
also, @Disch: This is a program I'm making. Sorry for the confusion. 0,o
This thread confuses me. It looks like you just copy/pasted an old thread from these boards.

What is the actual question here?

EDIT:

oh blah, I see your question now.


Please, can you tell me the functions and their arguments for creating, removing, and re-naming folders? PLEASE? Right now I just have my programs write a batch command to do those things (including accidentally making the un-removeable folder).


On windows there are:
CreateDirectory
MoveFile (to rename a directory)
RemoveDirectory

Documentation and examples are on MSDN:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365239(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365488(v=vs.85).aspx
Last edited on
ok, well that doesnt really help because I'm learning this on my own.

Example: Created Directory has (apparently) 2 arguments: directory name and security whatever.

What is security? is it a string? is it an integer? What's it's purpose? ect.... I would appreciate it if you either told me how to use all the arguments in these functions, or directed me to a place where I could get more specific information on how they work.

Thank you for your time!
Last edited on
In almost every instance where a Security Descriptor is required, passing NULL will cause a reasonable default to be used.

And string? How do you expect CreateDirectory to create your directory if you don't pass in the directory name? If this is the sort of thing you're struggling with, you need to step back and make sure you understand the tutorials.
kbw, you're not helping. I know how to use a string, its freaking basic. I'm taking about the stuff that isn't obvious, which if you can't infer please don't post.
@IWishIKnew
You really need to learn how to talk to people. You are arrogant, condescending, and rude. If you read the link Disch provided it tells you what you need to know. As kbw mentioned, the second param is optional and if you pass it NULL you will get default security inherited from the parent directory.
@IWishIKnew
What's been said was that you need to read each character of the user inputted string (for the folder name) and parse it. Using the HTML format of what each individual character (minus letters and numbers) is supposed to be. There is no need to get hostile because someone hasn't wrote the code for you. You have a hard time explaining your thoughts into words.

Take a step back and look at what your program does. Why is your program creating a batch file to begin with? Shouldn't your code be doing whatever batch you need done? There is a lot of anti-virus software out there that will flag that code as being hostile and threatening. Why can't you use your program to create the folders? I just started doing that myself, I'll show you an example: but I'm using boost libraries instead since the Windows ones are complicated (checking if the directory exists, etc.) and the boost ones provide portable, easier versions.

Going back to having the user enter the string for the folder name, you essentially will be trying to dummy proof their input (make sure someone can't enter "FolderName...") and make sure that whatever they enter will be accessible by the system.
ok. I'm sorry if i haven't been clear enough. I have asperger's syndrome, so I'll just explain everything:

I wrote a program that was supposed to allow you to create flash cards (i wrote it to help me study). One of the features in the program was the ability to save a 'set' of flash cards into a folder which the user would name THROUGH the program. The program would then write a batch file (a batch file containing a batch command to create the folder the user named) which would be executed to create the folder, and the program would then move (rename) the 'set' of flash cards (of data files) into the folder. This was done because I (at the time) did not know any C++ - specific functions that would allow me to create/remove directories without writing that batch file. I did do a search, but found nothing on how to create a folder with C++. That is why I used a batch file.

Now, when using the program if the user named their save "howdydoo?...", a folder would be created, regardless of unallowed characters. The files which were moved to that folder could not be viewed, and the folder could not be 'located' through a file search. When you tried to open the folder, a pop-up window would display the following: "The folder you have specified does not exist."

Since then I have created parsing functions to disallow such erroneous things to occur.

The questions I have now are specific only to the following funstions:

CreateDirectory()
RemoveDirectory()
MoveDirectory()

Like every function they come with arguments (naturally represented by variables which could be strings, integers, floats, etc...).

BOOL WINAPI CreateDirectory(
__in LPCTSTR lpPathName,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes
);


The only question I have for this one:

lpSecurityAttributes [in, optional]

A pointer to a SECURITY_ATTRIBUTES structure. The lpSecurityDescriptor member of the structure specifies a security descriptor for the new directory. If lpSecurityAttributes is NULL, the directory gets a default security descriptor. The ACLs in the default security descriptor for a directory are inherited from its parent directory.


yeah, yeah. I see that in the syntax example, but this description still does not explain what the hell an "lpSecurityDescriptor" even is. All I know so far is that I can call it with the argument "NULL" and it will work for me. From experience though, I have learned that knowing every aspect of somthing (or the way it works) can be extrememely useful.

Now, I descovered that You can only use 1 path name at a time with this function. I.E.: CreateDirectory(".\\dir1\\sdir"); can not work. I would end up haveing to split it in two. I.E: CreateDirectory(".\\dir1"); CreateDirectory(".\\dir1\\sdir");

Little things like that are what I really need to know. I am 'teaching' myself C++, so your help is very much appreciated.
forget it
Last edited on
I'd strongly suggest looking into the boost libraries since they're portable and allow a lot of features that standard C++ doesn't, like creating directories. They're just as easy to use as the standard (minus some long namespaces) and typically have more functionality than the C++ standard.
I haven't been able to understand the completely vague installation directions they have. I would assume it is because they are for either professionals, or people who know how to install third party libraries. Since I've never installed a third party library, and have ever been taught how, the directions are insufficient. Unless you can tell me what to "build", how to even "build" it, and where all the files even go, I'm not even going to consider trying to install it.

I would also appreciate it if someone would just give me the answer to my question.
Last edited on
If your question is how to create a directory and sub directory you can use SHCreateDirectoryEx http://msdn.microsoft.com/en-us/library/windows/desktop/bb762131%28v=vs.85%29.aspx and it's usage
1
2
std::wstring st = L"C:\\Users\\Sean\\Downloads\\test\\test\\test\\";//Downloads exists
	int ret = SHCreateDirectoryEx(NULL,st.c_str(),NULL);//if ret is 0 it succeeded 
kbw had a very good explanation for what the Security Attributes were. It's not easy stuff, and as he originally said, it's very rarely even needed unless you need to add R/W protection for users/groups etc. For a flash card game, this isn't necessary, and I'm sure there is plenty of things in C++ you don't know about. The Windows API isn't the place to start by trying to "know it all" because quite frankly, knowing the Win API really means you know nothing.

That aside, I can't personally answer your question. I took some networking classes and know how to modify the file/folder security permissions by hand, but there wasn't a need for it there (unless it contained critical information) and there definitely isn't a need for it here. If you're still persistent on actually learning what the attributes are, take a look here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa379560(v=vs.85).aspx

It's not going to be easy to understand because if you read what kbw said, you would have understood how much goes into making the attributes. People spend a lot of time taking care of security tokens. Again, it's not easy and unless absolutely necessary, it's best avoided.

As for the boost libraries, they're just like any other toolkit. It's not a simple double click to install, but it's by no means difficult either. It might require you to download MinGW or MSYS depending on what you have, but that's not really any issue anyways since both are great pieces of software.

The boost libraries are very contextual. It's hard for some people to understand the information, myself included, but I got lucky enough and found the MinGW setup on this site:http://nuwen.net/mingw.html

Check the link out, it includes not only Boost 1.5.0, but also the latest MinGW 4.7.1, and several other things that'll help you. Near the bottom is a link for MSYS if you would like it. I'd suggest it since it will come in handy later.

MSYS is simply a POSIX style shell. It has autotools support along with GNUMake. I know that might not make sense to you now, but all of it plays a huge role in installing third party libraries.

The benefit of downloading from nuwen's site is you don't have to worry about installing anything. You just extract the file to a directory (I suggest C:/MinGW) and you're good to go.

One last note, make sure you extract it to a directory that has no data in it, and you should really really try to avoid pathnames with spaces in them. The tools in the download don't do well with spaces.
Thank you Volatile Pulse. I will replace my current version on MinGW.

Just so that I dont (for some reason) mess up:

I have MinGW installed in my CodeBlocks program folder, so Im going to just back up the entire program and 'wing it'. Im going to delete MinGW, download nuwen's "distro", and if it doesn't work I'll post it.

It seems simple enough though, so I am downloading it now.
Last edited on
I have been running into several issues using the "newer" versions of MinGW so be aware that you might not be able to compile certain toolkits. Check everything that comes with Nuwen's version to see if it has what you want. The newest distribution of MinGW, (4.7.0 I believe) has been working well for me lately.

If all you want is the boost libraries, I'd just suggest Nuwen's distro since it's easy to install and has the boost libraries already coupled with it. I've been noticing that other toolkits (SFML, Fox, etc.) can't be installed with the newer MinGW versions due to the compiler/autotools being changed slightly. There is a thread on the Fox Toolkit forum that has a way to build their toolkit, however, with the updated MinGW distros.

Using the boost libraries almost feels like you're using the standard libraries and has a lot more functionality as well. You can also change C::B's executable toolchain under the Compiler Settings menu. There is an autodetect button, but you can also indicate specifically which path you want to use for each executable.

I hope everything works out for you. And if you have anymore issues post here.
Ok, I assumed it included MinGW in the "distro" pack, so I removed it from ythe Code::Blocks folder. Don't worry, I'm not a fool I backed it up (lol). I wrote a small program and tried it out and here is what I got as a compiler error:

"Boost test - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...


So, am I correct in assuming that the MinGW compiler is not part of this 'pack'? I did a quick search for "mingw32-gcc.exe" in the "distro pack" install directory (the directory i installed the distro pack" in) and I got absolutely nothing. It would appear that the MinGW executable wasn't even included.

So, should I put the compiler back into the program folder and just use the Boost part of that "pack", or am I missing a few steps?

I also want to mention that (somwhere) I read somthing about 'special compiler settings in code blocks' for the Boost #include files. Could someone clear that up for me?

Thank you!
Last edited on
I'd suggest following the instructions on Nuwen's site directly. If you do, the MinGW package and all of the extra tools are installed in C:\MinGW. This make it extremely easy since everything is in one easy place to find. Once you have that set up, all of the executables that C::B needs are in C:\MinGW\bin. The boost header files are all in the C:\MinGW\include directory and as long as you follow traditional instructions for boost headers (which are <boost/...>), you will be able to find those directories correctly.

As for the toolchain issue, read the last few lines up there. You need to make sure that you change C::B to find the executables. Mine aren't mingw32-gcc.exe, but just gcc.exe, g++.exe, etc. The Compiler's installation directory is C:\MinGW as well and I have never had an issue with it. Try changing the .exes to the above (remove the mingw32- prefix) and make sure your installation directory reflects the root directory for the compiler (again the auto-detect button might be able to help you).

Edit: In regards to the "special compiler settings", they may have been referring to the libraries (.a files). These are located in the lib directory of the installation. You can add them to the linker by typing the name of the library, minus the lib prefix and the .a extension. For example, libboost_thread.a would be added under the linker by typing boost_thread. The only issue with this is that it becomes global to every program you write them.

You may just want to add them per project basis so that you don't bloat your program.
Last edited on
alright. Well, i followed the instructions to the letter on nuwen's site. The installation was successful! Thank you.
Pages: 12