Append date to filename in linux

Info/Summary With bash scripting you can enclose commands in back ticks or parantheses. This works great for labling files, the following wil create a file name with the date appended to it. Methods Backticks – $ echo myfilename-“`date +”%d-%m-%Y”`” $(parantheses) – : $ echo myfilename-$(date +”%d-%m-%Y”) Example Usage: echo “Hello World” > “/tmp/hello-$(date +”%d-%m-%Y”).txt” (creates … Read more

Rename more than one column using withColumnRenamed

It is not possible to use a single withColumnRenamed call. You can use DataFrame.toDF method* data.toDF(‘x3’, ‘x4’) or new_names = [‘x3’, ‘x4’] data.toDF(*new_names) It is also possible to rename with simple select: from pyspark.sql.functions import col mapping = dict(zip([‘x1’, ‘x2’], [‘x3’, ‘x4’])) data.select([col(c).alias(mapping.get(c, c)) for c in data.columns]) Similarly in Scala you can: Rename all … Read more

Easiest way to rename a model using Django/South?

To answer your first question, the simple model/table rename is pretty straightforward. Run the command: ./manage.py schemamigration yourapp rename_foo_to_bar –empty (Update 2: try –auto instead of –empty to avoid the warning below. Thanks to @KFB for the tip.) If you’re using an older version of south, you’ll need startmigration instead of schemamigration. Then manually edit … Read more

Rename all files in a directory with a Windows batch script

A FOR statement to loop through the names (type FOR /? for help), and string search and replace (type SET /? for help). @echo off setlocal enableDelayedExpansion for %%F in (*120×90.jpg) do ( set “name=%%F” ren “!name!” “!name:120×90=67×100!” ) UPDATE – 2012-11-07 I’ve investigated how the RENAME command deals with wildcards: How does the Windows … Read more

Rename multiple files in cmd

Make sure that there are more ? than there are characters in the longest name: ren *.txt “???????????????????????????? 1.1.txt” See How does the Windows RENAME command interpret wildcards? for more info. New Solution – 2014/12/01 For those who like regular expressions, there is JREN.BAT – a hybrid JScript/batch command line utility that will run on … Read more

MongoDB rename database field within array

For what it’s worth, while it sounds awful to have to do, the solution is actually pretty easy. This of course depends on how many records you have. But here’s my example: db.Setting.find({ ‘Value.Tiers.0.AssetsUnderManagement’: { $exists: 1 } }).snapshot().forEach(function(item) { for(i = 0; i != item.Value.Tiers.length; ++i) { item.Value.Tiers[i].Aum = item.Value.Tiers[i].AssetsUnderManagement; delete item.Value.Tiers[i].AssetsUnderManagement; } db.Setting.update({_id: … Read more

How to rename file by replacing substring using batch in Windows [closed]

@echo off Set “Filename=how-to-rename-file.jpg” Set “Pattern=rename” Set “Replace=reuse” REM Call Rename “%Filename%” “%%Filename:%Pattern%=%Replace%%%” Call Echo %%Filename:%Pattern%=%Replace%%% :: Result: how-to-reuse-file.jpg Pause&Exit I give you other example for a loop of files: UPDATE: I’ve missed some things in the syntax ’cause fast-typing my last edit, here is the corrected code: @echo off Setlocal enabledelayedexpansion Set “Pattern=rename” Set … Read more

How do I move file a to a different partition or device in Node.js?

You need to copy and unlink when moving files across different partitions. Try this, var fs = require(‘fs’); //var util = require(‘util’); var is = fs.createReadStream(‘source_file’); var os = fs.createWriteStream(‘destination_file’); is.pipe(os); is.on(‘end’,function() { fs.unlinkSync(‘source_file’); }); /* node.js 0.6 and earlier you can use util.pump: util.pump(is, os, function() { fs.unlinkSync(‘source_file’); }); */

Renaming files using node.js

You’ll need to use fs for that: http://nodejs.org/api/fs.html And in particular the fs.rename() function: var fs = require(‘fs’); fs.rename(‘/path/to/Afghanistan.png’, ‘/path/to/AF.png’, function(err) { if ( err ) console.log(‘ERROR: ‘ + err); }); Put that in a loop over your freshly-read JSON object’s keys and values, and you’ve got a batch renaming script. fs.readFile(‘/path/to/countries.json’, function(error, data) { … Read more

Is rename() without fsync() safe?

No. Look at libeatmydata, and this presentation: Eat My Data: How Everybody Gets File IO Wrong http://www.oscon.com/oscon2008/public/schedule/detail/3172 by Stewart Smith from MySql. In case it is offline/no longer available, I keep a copy of it: The video here The presentation slides (online version of slides)