Create subfolder from suffix of filename then move file - windows

I have got several image files in one folder sharing the same filename but have a different suffix
i.e:
textures\texture_suffix.dds
textures\texture_suffix1.dds
...
textures\texture_suffix10.dds
Using a batch I want to create subfolders named Texture.Suffix, Texture.Suffix2 based on the suffix of the files under textures, then move the respective file into its subfolder and rename it 'texture.dds'.
Can this be done using batch file?
Thanks for any help.

cd textures
for /f %%i in ('dir /b /s') do (
md %%~ni
move %%i %%~ni\ )
pause
write these tags in a bat file and run the bat file in the same directory that includes textures directory

Related

Copy files listed in a txt file and put it in another directory

Im trying to copy multiples/hundreds of files using a text file and placing it in another directory
For example my source directory has this files.
09_yehey_123456.SENT
09_yohoo_987654.SENT
09_testy_789065.SENT
09_lolol_124125.SENT
09_hahah_241567.SENT
And the text file looks like this (this text file contains the files that I should only copy from the source directory)
09_yehey
09_yohoo
09_testy
Here's the code that i tried using
for /f "delims=" %%i in (files2.txt) do echo F|xcopy "C:\Users\username\source\%%i*" "C:\Users\username\Documents\dest\%%i"
PAUSE
the * from the source dir doesnt seem to work as a wildcard
Try like this :
for /f "delims=" %%i in (files2.txt) do (
copy /y "C:\Users\username\source\%%~ni*" "C:\Users\username\Documents\dest\"
)
PAUSE
As the names in the text file are not the same as the actual files you'll need wild cards.

Move multiple files from multiple folders to one folder

I am looking for a .bat file that can look inside multiple folders that contain sub-folders that are named the same and move their contents to a specified folder.
Folder Structure:
Main_folder
MainTextures_folder
Props_folder
--model1_subfolder
------Textures_subfolder
----------image files
--model2_subfolder
-------Textures_subfolder
----------image files
--model3_subfolder
-------Textures_subfolder
----------image files
--model4_subfolder
-------Textures_subfolder
----------image files
I need all image files moved from their Textures_subfolder to the MainTextures_folder.
Thanks for any help.
This expects model* folders under the props folder, and that each model* folder has a textures folder. The MainTextures folder is in the Main_folder.
It's untested and should move all files from each textures folder into the MainTextures folder.
#echo off
pushd "Main_folder\Props"
for /f "delims=" %%a in ('dir model* /b /ad') do (
move /-y "%%a\textures\*.*" "..\MainTextures"
)
popd
for /r "Props_folder" %%x in (*.jpg *.png *.bmp *.whatever) move "%%~fx" "MainTextures_folder"
This code will overwrite all existing files.

batch file to list all txt files from other directories

I am in the process of fetching all the .txt files from one directory to another (my current).
My current directory is
C:\USERS\MRAH
where i have the batch file and i have the code to fetch all .TXT files from the directory
dir E:\S_RUNS\12 month_STAR\S_2013\tst\*.txt /b >> INPUT_FILE_LIST.TXT
I am not able to fetch all the .TXT file which are in the E:\ DIREC into INPUT_FILE_LIST.TXT file on C:\USERS\MRAH
Can anyone let me know as to what should be code to fetch all the .txt file from one directory to another...
Thanks!
I'm not completely sure this will work on multiple directories but you could try it.
Cd E:\[path]
for /d %%a in (*) do (if %~xa == .txt echo %%a >> input_list.tmp)
for /f %%a in (input_list.tmp) do (copy %%a C:\USERS\MRAH)
note the batch file needs to be run from the E:[path]
also note you save it as a .tmp file to prevent it from logging itself
also instead of making an input_list file do it directly:
for /d %%a in (*) do (if %~xa == .txt copy %%a C:\users\MRAH)
Tell me if this doesn't work
Yours, Mona
Assume your current working directory is c:\testDir and you wanna copy all txt files from c:\source to d:\dest then use following content in a batch file
copy c:\source*.txt d:\dest

To copy entire subfiles to other (only one) folder without path in windows platform

I did lots of search however i couldnt achieve what i want to do :
I have a folder which contains lots of folders and files under it. I just want to copy entire JPEG files in this folder to another folder without copying previous path tree.
I used this batch command like that :
for /r "C:\source" %%f in ("*.JPG") do #copy %%f "C:\dest" /Y
It works some files which dont contain any space in the name of files. However, it doesnt work files which contains space in file name like that :
it can find and copy "aabb.JPEG"
it can not copy "aa bb.JPEG"
any solutions?
The following works great for me
#ECHO OFF
FOR /R "c:\source" %%F IN (*.jpg) DO (
copy "%%F" "c:\dest\" /Y
)

Read the filenames of group of files , make folders with specific file name(excluding extentions) than copy each file in their respective folder.

Read the filenames of group of files , make folders with specific file name(excluding extentions) than copy each file in their respective folder.
I had tried with this ,not working right
#echo off
for /F "tokens=1 delims =_" %%G in ('dir/b *.txt') do set testvariable=%%G
md %testvariable%
set "path=C:\Documents and Settings\USP\Desktop\"
set "path2=%testvariable%"
set "destpath=%path%%path2%"
copy *.txt %destpath%
You cannot create a folder with same name as a file on the same location.

Resources