How do I copy files? - drupal

I need to copy a file from one folder to another folder. How can I implement this in Drupal. Give me some ideas with working examples.

Second result on Google for "file copy, drupal"...
file_copy()
Copies a file to a new location.
This is a powerful function that in
many ways performs like an advanced
version of copy().
Checks if $source and $dest are valid
and readable/writable.
Performs a file
copy if $source is not equal to $dest.
If file already exists in $dest either
the call will error out, replace the
file or rename the file based on the
$replace parameter.

Related

Informatica Flat File source name

I am working on a project were we need to load flat file eg : (Gemstone_20220325.csv) I have given the source name as (Gemstone_*.csv) in script to search for the file in the path.
But it is failing with error , No such file .
Is that anything I am missing . Any idea on this is much appreciated .
You need to put either exact name or use a file list with the name of the file and then use indirect file type in the session that is reading the file.
You can use a pre session shell command like this ls -1 Gemstone_*.csv>/infa/home/tmp/Gemstone_filelist.txt. Or you can create a shell script too with this command for better control.
in the session that is reading this file, set the property to indirect file type and mention /infa/home/tmp/Gemstone_filelist.txt as file to be extracted.
Infa will pick files one by one and process them.
Once the file gets processed, delete it using a post session command task rm -f Gemstone_*..

Generate .php file rather than .html in docfx documentation

I have been generating documentation with Docfx and everything works fine. Docfx generates .html files which is as expected.
However, since html files an be embedded in php files, I am looking for a way to generate the files as .php files rather than .html which I don't find any information.
I need this feature because I use a PHP templating engine in my application and I wanted to insert template variables in the markdown files for PHP to resolve dynamic values when being loaded in browser.
If this is possible, I would want a guide on how to do this. For instance, if I could locate and modify the file extension in the source code where the files are created.
Thanks in advance.
There's no build-in feature for that. Since I ran into the same problem today, here's a small workaround to archive that (sample in powershell):
$destinationRoot = "path/to/doc"
[RegEx]$Search = '(\.html)"'
$Replace = '.php"'
ForEach ($File in (Get-ChildItem -Path $destinationRoot -Recurse -File)) {
(Get-Content $File.FullName) -Replace $Search,$Replace |
Set-Content $File.FullName
}
After that you have to rename the files via script, too (it's not part of that script). You can archive that via modify the Set-Content $File.FullName command. You may wish to delete the old file, too.
Keep in mind it will replace links in the content, too, if they end with .html", but pages normally will not end with that extension, so it's an acceptable trade-off. If you really ran into that problem, just append a # or something else to the URL.

Creating a terminal command in Minix

I want to create a command that runs an executable created by compiling a c program. I couldn't find a proper solution. Let's say I have a file named myprogram.c and compile it and have myprogram as . I want to type myprogram in any folder in my system and run it. How can I achieve this?
First find out what your PATH is
echo $PATH
For you this outputs
/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin/usr/X11R7/bin:usr/X11R‌​‌​6/bin:/usr/local/sbin:/usr/local/bin
Then assuming your program is in the /usr/myprog directory, append /usr/myprog to your PATH (don't forget to separate directories with a colon :)
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin/usr/X11R7/bin:usr/X11R‌​‌​6/bin:/usr/local/sbin:/usr/local/bin:/usr/myprog
Doing this tells the system when you don't specify an absolute path (like ./myprogram) to look in all the directories in PATH. It is good to add the absolute path of your executable to PATH because adding . to your PATH is frowned upon by some (see this question).
You have to add it in your PATH from your shell rc file
You place the executable into a directory that your shell already searches for programs, or you add your program's location to that list.
the $PATH environment variable contains this information. You can add myProgram's location to it, i.e. export PATH=$PATH:/new/dir, or just print out $PATH and copy myProgram into one of the paths listed there already.

how to mass change folder names in amazon s3 with a script

I uploaded a bunch of images but accidentally named the folders with spaces. Now you can't access them cause obviously urls cant have spaces.
I've downloaded the aws cli and was wondering how to change folder names? I've looked at the documentation but I'm still having trouble and hoping someone can help.
I've tried the below command without any success:
aws s3 mv "s3://mybucketname/firstfolder/second folder with spaces/" s3://mybucketname/firstfolder/secondfolderwithspaces/ --recursive
How do I change the name of "second folder with spaces" to "secondfolderwithspaces"?
Also, is there a way I can iterate through these folders? Something like
for folder in s3:/bucketname/firstfolder:
aws s3 mv "folder with spaces" folderwithspaces --recursive
I'd do it via a python script using the boto SDK:
import boto
conn = boto.s3.connect_to_region('ap-southeast-2')
bucket = conn.get_bucket('bucket-name')
for k in bucket.list():
if ' ' in k.key:
bucket.copy_key(k.key.replace(' ', '+'), bucket.name, k.key)
bucket.delete_key(k.key)
The script loops through each object, copies it to a new key (which is like a filename, but it includes the full path including the directory name), then deletes the old object. It fully executes within Amazon S3 -- the contents of the objects are not downloaded/uploaded.
Modify the replace command to suit your needs.
URLs can have spaces. You have to encode them. Space character becomes "%20".
If you have chrome or firefox, open the developper tools console, and type
encodeURI("second folder with spaces")
It prints
second%20folder%20with%20spaces
For the mass rename, it can't be done in the same way as you traditionally would on an OS (Linux/Windows/Mac). On S3, you cannot rename files, you must copy them. So you have to download their content, delete them, and new files.
Amazon S3 boto: How do you rename a file in a bucket?

Command similar to lndir to update the directory

The command lndir is used to create a copy of the original directory where files are soft links to the original counterparts. Is there a way to update the directory. e.g If there are new files created in the original directory the command or lndir used with the option should just create new files.
Thanks,
Gudge.
From the lndir man page
If you add files, simply run lndir again. New files will be silently added. Old files will be checked that they have the correct link.

Resources