批處理命令根據文件名創建文件夾並將文件/文件夾移動到創建的文件夾

[英]Batch command to create folder based on filename and move files/folders to created folder


Basically what I'm trying to do is create a folder from a filename, which this does:

基本上我要做的是從文件名創建一個文件夾,這樣做:

for %%i in (*.png) do mkdir "%%~ni"

for %% i in(* .png)do mkdir“%% ~ni”

After folder creation I'd like move a folder into this new folder.

創建文件夾后,我想將文件夾移動到這個新文件夾中。

move "other_folder" %%~ni

移動“other_folder”%% ~ni

4 个解决方案

#1


1  

Based on your now completely changed question:

基於您現在完全改變的問題:

If there was only one .png file in the working directory, then you could simply do it in one line at the Command Prompt:

如果工作目錄中只有一個.png文件,那么您只需在命令提示符下的一行中執行:

For %A In ("*.png") Do RoboCopy "other_folder" "%~nA" /E /MOVE >Nul

However, if you think about it, once the other_folder has been moved the first time, it is no longer there to be moved again! You would therefore need to instead copy it, then after all .png files have been processed, remove other_folder.

但是,如果您考慮一下,一旦第一次移動了other_folder,它就不再再被移動了!因此,您需要復制它,然后在處理完所有.png文件后,刪除other_folder。

At the Command Prompt: (two different commands, the first copies, the second removes)

在命令提示符處:(兩個不同的命令,第一個副本,第二個刪除)

For %A In ("*.png") Do RoboCopy "other_folder" "%~nA" /E > Nul
RD /S /Q "other_folder"

Similarly from a batch file:

同樣來自批處理文件:

@For %%A In ("*.png") Do @RoboCopy "other_folder" "%%~nA" /E > Nul
@RD /S /Q "other_folder"

Just take account that if anything goes wrong, (e.g. all of the content of other_folder doesn't copy), and you remove other_folder, you've lost that content.

請記住,如果出現任何問題,(例如,other_folder的所有內容都不會復制),並且您刪除了other_folder,那么您就丟失了該內容。

#2


1  

just extend the part to be executed by DO:

只需擴展DO要執行的部分:

for %%i in (*.png) do (
  mkdir "%%~ni"
  convert "%%i" --folder="%%ni\test.bmp"
)

(not sure, how your convert command works - above is a guess)

(不確定,你的轉換命令如何工作 - 上面是一個猜測)

#3


1  

Based on your title request, the bellow script will create a folder named after each *.png in the directory then move the matching file into the newly created file.

根據您的標題請求,bellow腳本將創建一個以目錄中每個* .png命名的文件夾,然后將匹配文件移動到新創建的文件中。

Batch:

for %%i in (*.png) do (mkdir "%%~ni" && move %%i %%~ni)

Command Prompt:

for %i in (*.png) do (mkdir "%~ni" && move %i %~ni)

#4


0  

Thanks everybody I was able to figure it out

謝謝大家,我能夠弄明白

for %%i in (*.png) do mkdir "%%~ni" && move "folder" "%%~ni"

for %% i in(* .png)do mkdir“%% ~ni”&& move“folder”“%% ~ni”


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/07/13/729fbbdb097d2934b02e65f8c5798805.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com