Create Folder using Jam - jam

I'm using jam in my project to automate building in Visual Studio.
I'm trying to move subdirectories and files from $folder to $folder1.
$folder is containing a project
$folder1 is empty.
I use File to copy files.
I try to copy files like this:
File ($folder1) : ($folder) ; //works
File ($folder1)\\subdir : ($folder)\\subdir //don't work
//etc...
But $folder1 is empty and does not contain a folder structure so File ($folder1)\\subdir : ($folder)\\subdir doesn't do anything because $folder1 is empty.
Is there way in Jam to create a folder depending if it exists or not?

I solved it by using MkDir
https://swarm.workshop.perforce.com/view/guest/perforce_software/jam/src/Jambase.html
It's important that you add the target as a Depends
Depends rule : $(1) ;
MkDir $(1) ;

Related

"for loop" to run rsync on relevant folders only

I have a folder contains around 650 folders (source), I generated a list of the relevant folders i want (final.txt).
i am trying to use a "for loop" to copy only the relevant sub-folders to a new location (target).
i keep getting the original content of the "source" copied to the "target".
i run:
for var in `cat final.txt` ; do rsync -ah $var source/ target/ ; done
I tried different syntax but can't seem to get what I need.
what am i doing wrong?
I expect to copy only the folders which name is in the final.txt list copied to the target (all "names" in the file are a single word, matching to some of the folder names for exactly)
ok after messing around I should have ran this (it works)
for var in `cat final.txt` ; do rsync -ah source/$var target/ ; done

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

Moving files into new subdirectory, except for existing folders?

A Redditor had written me a great script that allowed me to move all the files in a series of folders into a new subdirectory in all those folders called New. However, I also have pre-existing folders (namely just 1 called "Journals") that have had their files moved into a subdirectory called New, as well.
How would I modify the following script (on Windows) to not touch any folders within the folders, or perhaps not touch any folder called Journals?
For example, the current directory looks like:
Parent/Folder name/tons of files/
Parent/Folder name/Journals/tons of files
(folder name = random string of alphanumeric numbers in the thousands). Each folder has a ton of files, and a folder called Journals.
I would like:
Parent/randomstring folder/New/tons of files/
Parent/randomstring folder/Journals/tons of files
The code they wrote for me:
# Run from search root
cd "O:\..."
# Change this to taste
export NEWDIR=New
find . | egrep '(mp4$|jpg$|png$)' |
while read FILE
do
BASEDIR=$(dirname "$FILE")
mkdir "$BASEDIR/$NEWDIR" > /dev/null 2>&1
mv "$FILE" "$BASEDIR/$NEWDIR"
done
This code would do the following:
Parent/randomstring folder/New/tons of files/
Parent/randomstring folder/Journals/new/tons of files

looping files with bash

I'm not very good in shell scripting and would like to ask you some question about looping of files big dataset: in my example I have alot of files with the common .pdb extension in the work dir. I need to loop all of them and i) to print name (w.o pdb extension) of each looped file and make some operation after this. E.g I need to make new dir for EACH file outside of the workdir with the name of each file and copy this file to that dir. Below you can see example of my code which are not worked- it's didn't show me the name of the file and didn't create folder for each of them. Please correct it and show me where I was wrong
#!/bin/bash
# set the work dir
receptors=./Receptors
for pdb in $receptors
do
filename=$(basename "$pdb")
echo "Processing of $filename file"
cd ..
mkdir ./docking_$filename
done
Many thanks for help,
Gleb
If all your files are contained within the .Repectors folder, you can loop each of them like so:
#!/bin/bash
for pdb in ./Receptors/*.pdb ; do
filename=$(basename "$pdb")
filenamenoextention=${filename/.pdb/}
mkdir "../docking_${filenamenoextention}"
done
Btw:
filenamenoextention=${filename/.pdb/}
Does a search replace in the variable $pdb. The syntax is ${myvariable/FOO/BAR}, and replaces all "FOO" substrings in $myvariable with "BAR". In your case it replaces ".pdb" with nothing, effectively removing it.
Alternatively, and safer (in case $filename contains multiple ".pdb"-substrings) is to remove the last four characters, like so: filenamenoextention=${filename:0:-4}
The syntax here is ${myvariable:s:e} where s and e correspond to numbers for the start and end index (not inclusive). It also let's you use negative numbers, which are offsets from the end. In other words: ${filename:0:-4} says: extract the substring from $filename starting from index 0, until you reach fourth-to-the-last character.
A few problems you have had with your script:
for pdb in ./Receptors loops only "./Receptors", and not each of the files within the folder.
When you change to parent directory (cd ..), you do so for the current shell session. This means that you keep going to the parent directory each time. Instead, you can specify the parent directory in the mkdir call. E.g mkdir ../thedir
You're looping over a one-item list, I think what you wanted to get is the list of the content of ./Receptors:
...
for pdb in $receptors/*
...
to list only file with .pdb extension use $receptors/*.pdb
So instead of just giving the path in for loop, give this:
for pdb in $receptors/*.pdb
To remove the extension :
set the variable ext to the extension you want to remove and using shell expansion operator "%" remove the extension from your filename eg:
ext=.pdb
filename=${filename%${ext}}
You can create the new directory without changing your current directory:
So to create a directory outside your current directory use the following command
mkdir ../docking_$filename
And to copy the file in the new directory use cp command
After correction
Your script should look like:
receptors=./Receptors
ext=.pdb
for pdb in $receptors/*.pdb
do
filename=$(basename "$pdb")
filename=${filename%${ext}}
echo "Processing of $filename file"
mkdir ../docking_$filename
cp $pdb ../docking_$filename
done

How do I create a new directory called duplicates if a file already exists when renaming in c shell

I have a script that renames files with.JPEG ext to .jpg but if it renames one and it already exists I need it to create a new directory called duplicates and move the file there instead of overwritting it.
I have not tested this:
foreach j (*.JPEG *.JPG)
set target = $j:r.jpg
if (-e $target) then
mkdir -p duplicates # create directory if it doesn't already exist
mv $j duplicates/$target
else
mv $j $target
endif
end
But consider whether csh is the best tool for this kind of thing:
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
This will allow you to test for the existance of a file:
test -e img.jpg
You can test the existance of a file and if it does exist then move it to the duplicates folder. To create a folder called duplicates do the following:
mkdir duplicates
Hope that helps.

Resources