Renaming Files with Mathematica
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
I have a lot of video and text files. They all have the name: "Number-Suómething"
So for instance:
02-2.2-raKfcgvtavU.mp4
Is it possible to batch rename all the files using Mathematica to only "Number" ?
So for instance:
02.mp4
files-and-directories
add a comment |Â
up vote
6
down vote
favorite
I have a lot of video and text files. They all have the name: "Number-Suómething"
So for instance:
02-2.2-raKfcgvtavU.mp4
Is it possible to batch rename all the files using Mathematica to only "Number" ?
So for instance:
02.mp4
files-and-directories
1
I think it possible. Functions likeFileNames
,FileBaseName
andNotebookDirectory
might be helpful.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
yesterday
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
I have a lot of video and text files. They all have the name: "Number-Suómething"
So for instance:
02-2.2-raKfcgvtavU.mp4
Is it possible to batch rename all the files using Mathematica to only "Number" ?
So for instance:
02.mp4
files-and-directories
I have a lot of video and text files. They all have the name: "Number-Suómething"
So for instance:
02-2.2-raKfcgvtavU.mp4
Is it possible to batch rename all the files using Mathematica to only "Number" ?
So for instance:
02.mp4
files-and-directories
files-and-directories
asked yesterday
james
845418
845418
1
I think it possible. Functions likeFileNames
,FileBaseName
andNotebookDirectory
might be helpful.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
yesterday
add a comment |Â
1
I think it possible. Functions likeFileNames
,FileBaseName
andNotebookDirectory
might be helpful.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
yesterday
1
1
I think it possible. Functions like
FileNames
, FileBaseName
and NotebookDirectory
might be helpful.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
yesterday
I think it possible. Functions like
FileNames
, FileBaseName
and NotebookDirectory
might be helpful.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
yesterday
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
6
down vote
accepted
The following method does not require a specific fixed number of digits in the start of file name and does not depend on specific fixed non-numeric separator such as "-".
rename[name_]:=
RenameFile[
name,
StringCases[name,(x:DigitCharacter..)~~___~~".mp4":>x<>".mp4"][[1]]
]
1) Back up your files, - better make a new working copy of your directory.
2) Point Wolfram Language to that directory:
SetDirectory["path to your directory"]
3) Rename files:
rename /@ FileNames
You can also use CopyFile
instead of RenameFile
in order to keep the original file and place the renamed file in a directory of your choice. Because CopyFile
can copy and rename simultaneously.
Very nice ! Thanks a lot!
â james
22 hours ago
add a comment |Â
up vote
3
down vote
Simple
Just set the current working directory to the folder which contains the files:
SetDirectory["C\â¦"]
And then execute this command:
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
For .txt just do the same but replace the ".mp4" with ".txt"
Copy-Paste Code:
SetDirectory["C\â¦"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".txt"] & /@
FileNames["*.txt"]
add a comment |Â
up vote
1
down vote
You can try to map the following function over a list of full file names (with their full path). Use at your own risk.
rename = file [Function] RenameFile[
file,
FileNameJoin[
DirectoryName[file],
StringSplit[FileBaseName[file], "-"][[1]] <> "." <> FileExtension[file]
]
]
For example, you can find all files with extension "*.mp4"
in a given path path
with
FileNames[FileNameJoin[path, "*.mp4"]]
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
accepted
The following method does not require a specific fixed number of digits in the start of file name and does not depend on specific fixed non-numeric separator such as "-".
rename[name_]:=
RenameFile[
name,
StringCases[name,(x:DigitCharacter..)~~___~~".mp4":>x<>".mp4"][[1]]
]
1) Back up your files, - better make a new working copy of your directory.
2) Point Wolfram Language to that directory:
SetDirectory["path to your directory"]
3) Rename files:
rename /@ FileNames
You can also use CopyFile
instead of RenameFile
in order to keep the original file and place the renamed file in a directory of your choice. Because CopyFile
can copy and rename simultaneously.
Very nice ! Thanks a lot!
â james
22 hours ago
add a comment |Â
up vote
6
down vote
accepted
The following method does not require a specific fixed number of digits in the start of file name and does not depend on specific fixed non-numeric separator such as "-".
rename[name_]:=
RenameFile[
name,
StringCases[name,(x:DigitCharacter..)~~___~~".mp4":>x<>".mp4"][[1]]
]
1) Back up your files, - better make a new working copy of your directory.
2) Point Wolfram Language to that directory:
SetDirectory["path to your directory"]
3) Rename files:
rename /@ FileNames
You can also use CopyFile
instead of RenameFile
in order to keep the original file and place the renamed file in a directory of your choice. Because CopyFile
can copy and rename simultaneously.
Very nice ! Thanks a lot!
â james
22 hours ago
add a comment |Â
up vote
6
down vote
accepted
up vote
6
down vote
accepted
The following method does not require a specific fixed number of digits in the start of file name and does not depend on specific fixed non-numeric separator such as "-".
rename[name_]:=
RenameFile[
name,
StringCases[name,(x:DigitCharacter..)~~___~~".mp4":>x<>".mp4"][[1]]
]
1) Back up your files, - better make a new working copy of your directory.
2) Point Wolfram Language to that directory:
SetDirectory["path to your directory"]
3) Rename files:
rename /@ FileNames
You can also use CopyFile
instead of RenameFile
in order to keep the original file and place the renamed file in a directory of your choice. Because CopyFile
can copy and rename simultaneously.
The following method does not require a specific fixed number of digits in the start of file name and does not depend on specific fixed non-numeric separator such as "-".
rename[name_]:=
RenameFile[
name,
StringCases[name,(x:DigitCharacter..)~~___~~".mp4":>x<>".mp4"][[1]]
]
1) Back up your files, - better make a new working copy of your directory.
2) Point Wolfram Language to that directory:
SetDirectory["path to your directory"]
3) Rename files:
rename /@ FileNames
You can also use CopyFile
instead of RenameFile
in order to keep the original file and place the renamed file in a directory of your choice. Because CopyFile
can copy and rename simultaneously.
edited yesterday
answered yesterday
Vitaliy Kaurov
56.3k6157275
56.3k6157275
Very nice ! Thanks a lot!
â james
22 hours ago
add a comment |Â
Very nice ! Thanks a lot!
â james
22 hours ago
Very nice ! Thanks a lot!
â james
22 hours ago
Very nice ! Thanks a lot!
â james
22 hours ago
add a comment |Â
up vote
3
down vote
Simple
Just set the current working directory to the folder which contains the files:
SetDirectory["C\â¦"]
And then execute this command:
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
For .txt just do the same but replace the ".mp4" with ".txt"
Copy-Paste Code:
SetDirectory["C\â¦"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".txt"] & /@
FileNames["*.txt"]
add a comment |Â
up vote
3
down vote
Simple
Just set the current working directory to the folder which contains the files:
SetDirectory["C\â¦"]
And then execute this command:
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
For .txt just do the same but replace the ".mp4" with ".txt"
Copy-Paste Code:
SetDirectory["C\â¦"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".txt"] & /@
FileNames["*.txt"]
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Simple
Just set the current working directory to the folder which contains the files:
SetDirectory["C\â¦"]
And then execute this command:
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
For .txt just do the same but replace the ".mp4" with ".txt"
Copy-Paste Code:
SetDirectory["C\â¦"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".txt"] & /@
FileNames["*.txt"]
Simple
Just set the current working directory to the folder which contains the files:
SetDirectory["C\â¦"]
And then execute this command:
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
For .txt just do the same but replace the ".mp4" with ".txt"
Copy-Paste Code:
SetDirectory["C\â¦"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".mp4"] & /@
FileNames["*.mp4"]
RenameFile[#, StringTake[ToString[#] , 2] <> ".txt"] & /@
FileNames["*.txt"]
answered yesterday
henry
1,250423
1,250423
add a comment |Â
add a comment |Â
up vote
1
down vote
You can try to map the following function over a list of full file names (with their full path). Use at your own risk.
rename = file [Function] RenameFile[
file,
FileNameJoin[
DirectoryName[file],
StringSplit[FileBaseName[file], "-"][[1]] <> "." <> FileExtension[file]
]
]
For example, you can find all files with extension "*.mp4"
in a given path path
with
FileNames[FileNameJoin[path, "*.mp4"]]
add a comment |Â
up vote
1
down vote
You can try to map the following function over a list of full file names (with their full path). Use at your own risk.
rename = file [Function] RenameFile[
file,
FileNameJoin[
DirectoryName[file],
StringSplit[FileBaseName[file], "-"][[1]] <> "." <> FileExtension[file]
]
]
For example, you can find all files with extension "*.mp4"
in a given path path
with
FileNames[FileNameJoin[path, "*.mp4"]]
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can try to map the following function over a list of full file names (with their full path). Use at your own risk.
rename = file [Function] RenameFile[
file,
FileNameJoin[
DirectoryName[file],
StringSplit[FileBaseName[file], "-"][[1]] <> "." <> FileExtension[file]
]
]
For example, you can find all files with extension "*.mp4"
in a given path path
with
FileNames[FileNameJoin[path, "*.mp4"]]
You can try to map the following function over a list of full file names (with their full path). Use at your own risk.
rename = file [Function] RenameFile[
file,
FileNameJoin[
DirectoryName[file],
StringSplit[FileBaseName[file], "-"][[1]] <> "." <> FileExtension[file]
]
]
For example, you can find all files with extension "*.mp4"
in a given path path
with
FileNames[FileNameJoin[path, "*.mp4"]]
answered yesterday
Henrik Schumacher
41.3k259124
41.3k259124
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f183285%2frenaming-files-with-mathematica%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
I think it possible. Functions like
FileNames
,FileBaseName
andNotebookDirectory
might be helpful.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
yesterday