create folders based on a file name and move those files into that folder

眉间皱痕 提交于 2019-12-14 03:22:05

问题


I am a novice in creating automated tasks. I need to create folders based on a file name and move those files into that folder. There are instructions, but I am a little scared to try...little help?


回答1:


Split this into two steps (assume using C++ in Windows OS):

  1. Create a folder.

    #include <Windows.h>
    void create_folder(char* Path)
    {
        char DirName[256];
        char* p = Path;
        char* q = DirName;  
    
        while(*p)
        {
            if (('\\' == *p) || ('/' == *p))
            {
                if (':' != *(p-1))
                {
                    CreateDirectory(DirName, NULL);
                }
            }
            *q++ = *p++;
            *q = '\0';
        }
        CreateDirectory(DirName, NULL);
    }
    
  2. Write the file to the folder you just created (as you normally do).



来源:https://stackoverflow.com/questions/20923035/create-folders-based-on-a-file-name-and-move-those-files-into-that-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!