rename

python os.rename “”cannot create a file when that file already exists

China☆狼群 提交于 2019-12-24 16:58:20
问题 K.. I'm just using a simple script I found here: import os from os import rename, listdir print os.listdir(".") for filename in os.listdir("."): if filename.startswith("colon-"): print filename os.rename(filename, filename[7:]) I need to basically take all files like colon-21.mp3 converted to 21.mp3. But I get the error CANNOT CREATE A FILE WHEN THAT FILE ALREADY EXISTS. How does one solve this? I am using Windows 7. 回答1: The problem is right here: os.rename(filename, filename[7:]) Python

How to move a file in C

a 夏天 提交于 2019-12-24 14:28:25
问题 I need to move a file from an input to a certain folder, however, 'rename' keeps crashing the entire application. char start[50]; const char dest = "C:\Windows\System32\oobe\info\backgrounds\supertemp.JPG"; printf("Please enter file to move \n"); fgets(start, sizeof(start), stdin); if (rename(start, dest) == 0){ printf("Success \n"); } else{ printf("Failed %s ", GetLastError()); } It always crashes at ' if(rename(start, dest) ==0)'. I don't ever get as far as retrieving an error value. Any

How to rename files using a list file?

笑着哭i 提交于 2019-12-24 13:12:53
问题 I have 100s of files that I would like to rename in a specific manner according to a correlated list. Rather than repeating the same cmdlets, as below, I would like to point the cmdlet to a couple of list files (below) containing the old and new names, say old.txt and new.txt. How do I do this using PowerShell? Example: Rename-Item -Path "E:\MyFolder\old1.pdf" -NewName new1.pdf Rename-Item -Path "E:\MyFolder\old2.tif" -NewName new2.pdf Rename-Item -Path "E:\MyFolder\old3.pdf" -NewName new3

Using Powershell to recursively rename directories using a lookup file

让人想犯罪 __ 提交于 2019-12-24 12:12:36
问题 I need to rename a lot of directories and their sub directories. I have a csv file which contains the old directory names and the required new name. 1,blah,old_name1,new_name2,wibble 2,foo,old_name2,new_name2,bar 3,john,old_name3,new_name3,paul 4,george,old_name4,new_name4,ringo Note that some of the directory names are old_name1-morestuffhere which need to be renamed to new_name1-morestuffhere I know broadly how I'd do this in bash: mv -r `cat file.csv | awk -F, '{print $3* $4*}'` ..but I'm

File name after MediaStore.Images.Media.insertImage

痴心易碎 提交于 2019-12-24 10:45:13
问题 I am using MediaStore.Images.Media.insertImage(ContentResolver cr, String imagePath, String name, String description) function to insert a newly created image into gallery. System is naming the file by default, but it's diferent than names of pictures taken by orginal app (Time stamp). Is there easy way to set it up? 回答1: I use something like this Uri u; File fi = new File("/sdcard/tmp"); try { u = Uri.parse(android.provider.MediaStore.Images.Media.insertImage(getContentResolver(), fi

PHP rename files from CSV

99封情书 提交于 2019-12-24 10:39:13
问题 I am working on some PHP to rename photos in a directory to something else based on data from a CSV file. The CSV has three columns: Number, FirstName and LastName. The original names of the photos are " FirstName LastName .jpg". The new names should be " Number .jpg". I do this by cycling through the lines of the CSV, making the old name by putting FirstName and LastName together, making the new name by getting the number and renaming the files. However, I have two problems: The first is

Scripting for file management with a very large amount of files

佐手、 提交于 2019-12-24 09:39:33
问题 I have a three OSX machine setup that was using syncthing to keep shared drives synchronized remotely. Someone made some mistakes and a lot of files ended up getting renamed. So all throughout this drive I have situations where there's a file of size 0KB named,for example, file.jpg and another file with real size named file.sync-confilct201705-4528.jpg . I need to search the entire drive recursively and while I find a file with the sync-conflict string in it, check to see if there is the same

Renaming a tree node dynamically outside of contextmenu in jstree

随声附和 提交于 2019-12-24 09:14:04
问题 I use the code below to successfully create a new tree node in jstree outside of contextmenu. My question is how can you dynamically RENAME the text in a tree node in a similar manner outside of the contextmenu? Is there a .jstree("rename" ....) function that can be called to accomplish this? Much appreciated! $("#RequirementsTree").jstree("create", null, "last", {"data" : "new_node_text", "state" : "open", "attr" : { "id" : "new_node_id", "name" : "requirement" }, }); I've tried the

What is the equivalent of Project->Rename in Xcode 4

与世无争的帅哥 提交于 2019-12-24 04:52:05
问题 Xcode 3 had the easy to use Project-> Rename in case I wanted to change the name of my app being developed. I don't see the option in Xcode 4 anymore. Whats the best way to rename your app without any crashes? Thanks.. 回答1: ⌘+1, click the blue node with the project name, wait a second, click again (the name becomes editable). That's it. 回答2: This is answered here as well Renaming projects in Xcode 4 来源: https://stackoverflow.com/questions/6077876/what-is-the-equivalent-of-project-rename-in

Find and rename all pictures with incorrect file extension

走远了吗. 提交于 2019-12-24 03:23:30
问题 I'm looking for a way to automate renaming all images with a wrong filename extension. So far I at least found out how to get the list of all these files: find /media/folder/ -name *.jpg -exec file {} \; | grep 'PNG\|GIF' > foobar.txt find /media/folder/ -name *.png -exec file {} \; | grep 'JPEG\|GIF' >> foobar.txt find /media/folder/ -name *.gif -exec file {} \; | grep 'JPEG\|PNG' >> foobar.txt However, I would also like to automate the renaming. I tried things like find /media/folder/ -name