Moving files with specific file name & extension - windows

I'd like to create a batch file under windows to move files with specific file names. I'd like to move all the files with txt extension and filename starting with "HH", and moving them only from root, sub directories excluded. And if a file with the same name is already exist in the destination directory I'd like to auto rename files instead of overwriting. Is it possible to do?

You can simply use:
move c:\HH*.txt destination_directory

Related

Replace files in multiple folders, whose name includes destination folder name

I have very little experience with the command line and I'm trying to do something very complicated (to me).
I have a directory with A LOT of subfolders and files in them. All file names contain the parent folder name, e.g.:
Folder1
data_Folder1.csv
other_file_Folder1.csv
Folder2
data_Folder2.csv
other_file_Folder2.csv
In another folder (all in one directory), I have a new version of all the data_FolderX.csv files and I need to replace them in the original folders. I cannot give them another name because of later analyses. Is there a way to replace the files in the original folders with the new version, in the command line?
I tried this Replacing a file into multiple folders/subdirectories but didn't work for me. Given that I have many .csv files in the derectories, I don't want to replace them all, so I don't think I should do it based on the file extension. I would also like to note that the name "FolderX" contains several other _, so in principal, I want to replace the .csv file starting with data in the FolderX.
Can anyone help?
Thanks in advance!

Windows Script to Recursively Copy Files and add directory name prefix

I'm need a script to recursively copy a set of files from a folder and all the subfolders to a new folder. I do not want the directory structure copied. But I want to add the original directory name (not the full path) as a prefix to the copied file.
For example...copy
c:/photos/date1/photo1.jpg
c:/photos/date1/photo2.jpg
c:/photos/date1/photo3.jpg
c:/photos/date2/photo1.jpg
c:/photos/date2/photo2.jpg
c:/photos/date2/photo3.jpg
to:
c:/newfolder/date1-photo1.jpg
.....date1-photo2.jpg
.....date1-photo3.jpg
.....date2-photo1.jpg
.....date2-photo2.jpg
.....date2-photo3.jpg
I have this for loop to do the original copy which works just fine. But I am stuck at how to add the directory name as a prefix.
for /r %d in (*) do copy "%d" "x:\newfolder"
Appreciate advise/suggestions.

Copying the first 'n' files from each subfolder Unix

My folder structure is as follows :
and so on.
How do I copy the first file from each folder and rename them (maybe with the parent folder's name) so as to not ending up replacing them?
P.S :
I want to store them in a new folder with the same sub directories as source but with just one .wav file in each. And yes, in shell script or
Main_Folder/sub_folder_1/abc.wav
Main_Folder/sub_folder_1/def.wav
Main_Folder/sub_folder_2/abc.wav
Main_Folder/sub_folder_2/def.wav
Main_Folder/sub_folder_3/abc.wav
Main_Folder/sub_folder_3/def.wav
This folder structure repeats for all the sub_folders under the main_folder.
I want the output to look like :
New_Main_Folder/sub_folder_1/abc.wav
New_Main_Folder/sub_folder_2/abc.wav
New_Main_Folder/sub_folder_3/abc.wav

can we rename first suffix of file from all subfoldes if found through batch file?

I am renaming a resource files which first extension is 'hi-IN'. Now I need such a batch file which is change first extension to 'mr-IN' in a sub folders recursively. Some sub folders have no resource files.
file names are like this :
home.hi-IN.resx
home.en-GB.resx
index.hi-IN.resx
index.en-GB.resx
then output should be :
home.mr-IN.resx
home.en-GB.resx
index.mr-IN.resx
index.en-GB.resx
can we do this from batch script?

I'm looking for a script that will rename files and place them in a new folder

Essentially what I am looking to create is a script that will rename files in a folder, create a new folder with a specific name and place the renamed file in that new folder.
So, for instance, let's say that I had 2 files called:
test-spa.txt
test-ger.txt
I would then want to create 2 folders called spa and ger, respectively, place the appropriate file into each folder then rename the file by removing the language component; the resulting files in each folder would be test.txt.
Thanks,
Jaime
So here is the simple solution I came up with to create folders and place specific files in them. So long as I have the bat file in the same folder it works great:
#echo off
md spa ger
move file.txt EN\file.txt
move file-spa.txt spa\file.txt
move file-ger.txt ger\file.txt
I'm wondering if there is something missing that may cause an issue, such as specifying that this should only work in the current directory?

Resources