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

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?

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!

Looking for a script to move files into folders based on a variable in the filename

I have a folder of images I would like to automatically organize into sub folders based on a variable in the filenames. I'm new to scripting and I've tried to best explain what I would like below:
For example:
If files contains "BO" then create new folder called "Boucle" in same directory then add files that contain "BO"
If files contains "CW" then create new folder called "Cross" in same directory then add files that contain "CW"
I would like to run this in Automator and have some ability to add new variables in the future
Ideally, the creation of these new sub folders can happen in the same directory location I feed into the script.
Thank you!
I've tried some basic scripting but I think the variables are throwing me
for f in "$#"
do
if [[$f == "BO"]]
then
mkdir in "$#" "${BOUCLE WOOL}"
fi
done

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

Move .X to parent folder (Windows)

I have a specific structure wherein I need to move some files.
Example:
C:\Root\Projects\Project1\Draft
C:\Root\Projects\Project2\Draft
etc.
I want to move files of a specific type, in this case .pdf.
How would I go about scanning all "Draft" folders for .pdf files, and then moving them to the parent ProjectX folder and deleting the "Draft" folders?
I would prefer to have a .bat I could run for this, preferably running from C:\Root.
Being a novice, I assumed it was in the logic ballpark of:
Find files of type .pdf in folders named C:\Root\Projects\*\Draft
Move found files to ./ (parent)
Find folders in C:\Root\Projects\*\ named Draft
Delete found folders
However, I'm not exactly a wiz with commands.
Any help appreciated.

Moving files with specific file name & extension

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

Resources