logo elektroda
logo elektroda
X
logo elektroda

copying the contents of a folder in CMD

Domino_2 16374 8
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 14814604
    Domino_2
    Helpful for users
    Hello, the matter seems simple, but I still have a syntax error.

    I would like to copy the contents of a folder in cmd which will have a space and the folder name will change over time.

    I can enter the folder via:

    cd C:\Dr.WEB*


    However, I can not do this option anymore:

    copy C:\Instalki\Dr.WEB*\*.* C:\Temp


    It doesn't work either

    copy "C:\Instalki\Dr.WEB*\*.*" C:\Temp


    Is it feasible in cmd?
  • ADVERTISEMENT
  • #3 14815303
    marek003
    Level 40  
    I will only specify that:

    cd C:\Dr.WEB*
    copy *.* C:\TEMP


    Or

    cd C:\Dr.WEB???
    copy *.* C:\TEMP


    this will work correctly when there will be no more than one Dr.WEB directory ... (and interesting fact: or the name of the file that begins with this)

    When the main directory will be e.g. Dr.WEB1 and Dr.WEB2, the copying will take place from one of the directories, but from which (at the moment) I am not able to determine :) whether it's the name or the date of creation or the physical space on the disk.
    And if the file name starts like this, everything will be copied from the root directory.
  • ADVERTISEMENT
  • Helpful post
    #4 14815360
    iagre
    Level 35  
    Put asterisks after the quotation marks. Moreover, in CMD, do not do any operations with wildcards (question mark and asterisk) on files and directories that they have more than one period in their name , because you may get a result inconsistent with expectations and common sense - CMD with wildcards digest only one dot in a file or directory name.
  • #5 14815514
    Domino_2
    Helpful for users
    marek003 wrote:
    I will only specify that:

    cd C:\Dr.WEB???
    copy *.* C:\TEMP




    Yes, I know it will work because I have tested it before.

    But I'm more interested in the problem itself, why you can't do it with a single line, without going into a directory and then copying everything.


    Do you have any idea?

    Added after 2 [minutes]:

    iagre wrote:
    Put asterisks after the quotation marks. Moreover, in CMD, do not do any operations with wildcards (question mark and asterisk) on files and directories that they have more than one period in their name , because you may get a result inconsistent with expectations and common sense - CMD with wildcards digest only one dot in a file or directory name.


    This is interesting, I did not know that he can only do with one dot.
  • ADVERTISEMENT
  • #6 14815534
    penknife
    Level 21  
    one line (untested, to be placed in .bat or .cmd):
    for /f "tokens=*" %%d in ('dir /b /ad c:\* ^|find /i "Dr.WEB"') do echo copy "C:\%%~d\*.*" C:\TEMP\

    PS echo is for testing, remove it if the above syntax works correctly
  • ADVERTISEMENT
  • Helpful post
    #7 14815564
    clubs
    Level 38  
    Another solution in whip

    Code: Bash
    Log in, to see the code
  • #8 14815601
    iagre
    Level 35  
    I forgot about it before. :( Take an interest in the command xcopy - significantly expanded and improved ...
  • #9 14816093
    Domino_2
    Helpful for users
    iagre wrote:
    I forgot about it before. :( Take an interest in the command xcopy - significantly expanded and improved ...


    xcopy was the first command I started testing, but it also failed in this form.

    Added after 2 [hours] 3 [minutes]:

    clubs wrote:
    Another solution in whip

    Code: Bash
    Log in, to see the code


    Your solution won. It works. Thanks.

Topic summary

The discussion revolves around copying the contents of a folder with a variable name containing spaces using the Command Prompt (CMD). The user encounters syntax errors when attempting to use wildcards in the copy command. Various solutions are proposed, including using the `cd` command to navigate to the directory first and then executing the copy command, as well as using a `for` loop to dynamically handle folder names. The importance of handling file names with multiple periods and the potential use of the `xcopy` command are also mentioned. Ultimately, a working solution is confirmed by the user.
Summary generated by the language model.
ADVERTISEMENT