|
|
|
|
|
|
|
|
|
|
区切り |
\ |
/ |
|
\ |
\ |
\
/ |
\ |
System.getProperty("file.separator")
File.separator
File.separatorChar |
Path.DirectorySeparatorChar |
; |
: |
|
|
|
|
|
System.getProperty("path.separator")
File.pathSeparator
File.pathSeparatorChar |
Path.PathSeparator |
パス名 |
ドライブ:ディレクトリ\ファイル.拡張子 |
ディレクトリ/ファイル |
|
|
Set fs =
WScript.CreateObject("Scripting.FileSystemObject")
path = fs.BuildPath("ディレクトリ", "ファイル.拡張子") |
|
char path[_MAX_PATH];
_makepath(path, "ドライブ", "ディレクトリ", "ファイル", "拡張子" ); |
File path = new File("ディレクトリ",
"ファイル.拡張子"); |
string path = Path.Combine("ディレクトリ", "ファイル.拡張子"); |
%~d変数 |
|
|
|
drive = fs.GetDriveName("パス") |
|
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath("パス", drive, dir, fname, ext ); |
|
string drive = Directory.GetLogicalDrives("パス"); |
%~p変数 |
dirname パス |
|
|
dir = fs.GetParentFolderName("パス") |
|
String dir = path.getParent(); |
string dir = Path.GetDirectoryName("パス"); |
%~nx変数 |
basename パス |
|
|
name = fs.GetBaseName("パス") |
|
String name = path.getName(); |
string name = Path.GetFileName("パス"); |
%~n変数 |
|
|
|
fname = fs.GetFileName("パス") |
|
int n = name.lastIndexOf('.');
String fname = (n >= 0) ? name.substring(0, n) : name; |
string fname =
Path.GetFileNameWithoutExtension("パス"); |
%~x変数 |
|
|
|
ext = fs.GetExtensionName("パス") |
|
int n = name.lastIndexOf('.');
String ext = (n >= 0) ? name.substring(n + 1) : ""; |
string ext = Path.GetExtension("パス"); |
%~f変数 |
|
|
|
drive = fs.GetAbsolutePathName("相対パス") |
|
char path[_MAX_PATH];
_fullpath(path, "相対パス", sizeof(path)); |
String path = new
File("相対パス").getAbsolutePath(); |
string path = Path.GetFullPath("相対パス"); |
一覧 |
dir * |
ls * |
FILES "*" |
Dim name As String
name = Dir("*") '1番目
Do While name <> ""
〜
name = Dir() '2番目以降
Loop |
Set f = fs.GetFolder("ディレクトリ")
For Each n In f.Files
〜
Next
For Each n In f.SubFolders
〜
Next |
|
WIN32_FIND_DATAA ffdata;
HANDLE hFindFile=FindFirstFile("*",&ffdata);
if(hFindFile!=INVALID_HANDLE_VALUE){ //検索成功
if(ffdata.cFileName[0]!='\0'){
//ffdata:1番目
〜
}
while(FindNextFile(hFindFile,&ffdata)){
//ffdata:2番目以降
〜
}
FindClose(hFindFile);
} |
File f=new File("ディレクトリ");
String[] list = f.list();
String[] list = f.list(new
FilenameFilter() {
public boolean accept(File dir, String name) {
return true; //条件を自分で記述
}
});
File[] flist = f.listFiles(); |
サブディレクトリの取得
string[] dirs = Directory.GetDirectories("パス","*");
ファイル一覧の取得
string[] files = Directory.GetFiles("パス","*");
ファイルとディレクトリ一覧の取得
string[] files = Directory.GetFileSystemEntries("パス","*"); |
コピー |
copy 元 先 |
cp 元 先 |
COPY "元" TO "先" |
FileCopy "元", "先" |
fs.CopyFile "元", "先"
fs.CopyFolder "元", "先" |
|
CopyFile |
FileChannel
#transferFrom()
#transferTo() |
File.Copy("元", "先"); |
移動 |
move 元 先 |
mv 元 先 |
|
|
fs.MoveFile "元", "先"
fs.MoveFolder "元", "先" |
|
MoveFileEx |
|
File.Move("元", "先"); |
改名 |
ren 旧 新 |
mv 旧 新 |
NAME "旧" AS "新" |
Name "旧" As "新" |
Set f = fs.GetFile("旧")
f.Name "新" |
|
CFile::Rename("旧","新"); |
new File("旧").renameTo(new
File("新")); |
File.Move("旧", "新"); |
削除 |
del 対象 |
rm 対象 |
KILL "対象" |
Kill "対象" |
fs.DeleteFile "対象" |
|
CFile::Remove("対象"); |
new File("対象").delete(); |
File.Delete("対象"); |
ディレクトリ操作 |
cd |
pwd |
|
CurDir("ドライブ") |
|
|
_getcwd
_getdcwd |
System.getProperty("user.dir") |
Directory.GetCurrentDirectory();
Environment.CurrentDirectory; |
cd 先
chdir 先 |
cd 先 |
|
ChDrive "ドライブ"
ChDir "先" |
|
|
_chdrive(ドライブ番号);
_chdir("先"); |
|
Directory.SetCurrentDirectory("先");
Environment.CurrentDirectory = "先"; |
md 新
mkdir 新 |
mkdir 新 |
|
MkDir "新" |
fs.CreateFolder "対象" |
|
_mkdir("新"); |
new File("新").mkdir(); |
Directory.CreateDirectory("新"); |
MkDirsは自作 |
new File("新").mkdirs(); |
rd 対象
rmdir 対象 |
rmdir 対象
rm -r 対象 |
|
RmDir "対象" |
fs.DeleteFolder "対象" |
|
_rmdir("対象"); |
new File("対象").delete(); |
Directory.Delete("対象"); |
一時ファイル |
|
|
|
|
|
|
GetTempPath |
String dir = System.getProperty("java.io.tmpdir") |
string dir = Path.GetTempPath(); |
|
|
|
|
|
FILE *tmp = tmpfile();
char tmp[] = "接頭辞XXXXXX";
int fd = mkstemp(tmp); |
GetTempFileName |
File tmp = File.createTempFile("接頭辞",
"拡張子"); |
string tmp = Path.GetTempFileName(); |
|
|
|
|
|
|
|
|
|
|
属性取得 |
attrib 対象
dir /q
%~a変数 |
ls -l 対象 |
|
Dim stat As Integer
stat = GetAttr("対象") |
Set f = fs.GetFile("対象")
f.Attributes |
struct stat st;
stat("対象", &st); |
CFileStatus stat;
CFile::GetStatus("対象",stat); |
File f=new
File("対象");
f.canRead() |
FileAttributes a = File.GetAttributes("対象");
FileInfo fi = new FileInfo("ファイル名");
a = fi.Attributes; |
属性変更 |
attrib 属性 対象 |
chmod 属性 対象
chown 属性 対象 |
|
SetAttr "対象", 属性 |
f.Attributes = 属性 |
|
CFileStatus stat={ 属性 };
CFile::SetStatus("対象",stat); |
File f=new File("対象");
f.setReadOnly();
f.setLastModified(時刻); |
File.SetAttributes("対象", 属性);
fi.Attributes = 属性; |
存在チェック |
dir 対象 >nul
2>&1
&& echo 有り |
|
|
Dir("ファイル") <> "" |
fs.DriveExists("ドライブ")
fs.FileExists("対象")
fs.FolderExists("対象") |
access("対象", F_OK)==0 |
|
f.exists() |
new DriveInfo("ドライブ").IsReady
Directory.Exists("対象")
File.Exists("対象")
fi.Exists |
ディレクトリ |
|
|
|
(stat And vbDirectory) <> 0 |
|
S_ISDIR(st.st_mode)
S_ISREG(st.st_mode) |
stat.m_attribute & CFile::directory |
f.isDirectory()
f.isFile() |
(a & FileAttributes.Directory) != 0 |
読み取り専用 |
|
|
|
(stat And vbReadOnly) <> 0 |
|
access("対象",R_OK)==0 && access("対象", W_OK)!=0 |
stat.m_attribute & CFile::readOnly |
f.canRead() && !f.canWrite() |
(a & FileAttributes.ReadOnly) != 0
fi.isReadOnly |
隠しファイル |
|
|
|
(stat And vbHidden) <> 0 |
|
|
stat.m_attribute & CFile::hidden |
f.isHidden() |
(a & FileAttributes.Hidden) != 0 |
ファイル長 |
%~z変数 |
wc -c ファイル名 |
|
Dim len As Long
len = FileLen("ファイル名") |
|
st.st_size |
Long len = stat.m_size; |
f.length() |
fi.Length |
日時 |
%~t変数 |
|
|
FileDateTime("対象") |
f.DateCreated
f.DateLastModified |
st.st_ctime
st.st_mtime
st.st_atime |
stat.m_ctime
stat.m_mtime
stat.m_atime |
f.lastModified() |
fi.CreationTime
fi.LastWriteTime
fi.LastAccessTime |
|
|
|
|
|
|
|
|
|
|